// Admin Dataset

// 2017

use "$Endline_dtRaw/admin/escolas17_newversion.dta", clear

label variable escola_id "School ID"
label variable regime_de_ensino "Type of school"
label variable nome_da_escola "School name"
label variable n_da_escola "School number"
label variable numero_de_turnos_na_escola "Number of parts of the day with classes"
label variable ultima_classe_ensinada_na_escola "Highest class taught"
label variable n_de_horas_por_turno_manha "Duration morning period (in hours)"
label variable n_de_horas_por_turno_tarde "Duration afternoon period (in hours)"
label variable n_de_horas_por_turno_noite "Duration night period (in hours)"

label variable director "School director name"
label variable idade_director "Director age"
label variable n_de_telefone "Director phone number"
label variable nivel_academico_d "Director education"
label variable especialidade_d "Director speciality"
label variable nome_do_sub_director_pedagogico "Deputy director name"
label variable nivel_academico_sd "Deputy director education"
label variable especialidade_sd "Deputy director speciality"

label variable n_de_horas_como_director_d "Director hours dedicated to director duties"
label variable n_de_horas_como_director_sd "Deputy director hours dedicated to director duties"
label variable n_de_horas_como_docente_d "Director hours dedicated to teaching"
label variable n_de_horas_como_docente_sd "Deputy director hours dedicated to teaching"

label variable data_dia "Date of completing the form (DAY)"
label variable data_mes "Date of completing the form (MONTH)"
label variable data_ano "Date of completing the form (YEAR)"

rename escola_id 							school_id
rename regime_de_ensino  					school_type
rename nome_da_escola  						school_name
rename n_da_escola  						school_number
rename numero_de_turnos_na_escola  			number_periods
rename ultima_classe_ensinada_na_escola  	highest_grade
rename n_de_horas_por_turno_manha  			morning_hours
rename n_de_horas_por_turno_tarde  			afternoon_hours
rename n_de_horas_por_turno_noite  			night_hours
rename director  				 			director_name
rename idade_director  						director_age
rename n_de_telefone  						director_tel
rename nivel_academico_d  					director_edu
rename especialidade_d  					director_spec
rename nome_do_sub_director_pedagogico  	deputy_name
rename nivel_academico_sd  					deputy_edu
rename especialidade_sd  					deputy_spec
rename n_de_horas_como_director_d  			director_hoursdir
rename n_de_horas_como_director_sd  		deputy_hoursdir
rename n_de_horas_como_docente_d  			director_hoursteach
rename n_de_horas_como_docente_sd  			deputy_hoursteach
rename data_dia  							date_day
rename data_mes  							date_month
rename data_ano								date_year

drop school_type school_number

replace highest_grade = . if highest_grade==99

foreach var in morning_hours afternoon_hours night_hours{
replace `var' = . if inlist(`var',0,99)
replace `var' = 3.5 if `var'==3.3
replace `var' = 4.5 if `var'==4.3
}

*** figure out why 3.3 and 4.3 are not being replaced

foreach var in director_name director_edu director_spec deputy_name deputy_edu deputy_spec{
replace `var' = "" if `var'=="999                           "
replace `var' = "" if `var'=="999                 "
}

replace director_age=. if director_age==99
replace director_age=. if director_age==18

*** 18 years old must be a misstake, CHECK!

replace director_tel = . if director_tel==999

foreach var in director_hoursdir deputy_hoursdir director_hoursteach deputy_hoursteach{
replace `var' = . if `var'==99
}

replace director_hoursdir = . if director_hoursdir==0 & director_hoursteach==0
replace director_hoursteach = . if director_hoursdir==. & director_hoursteach==0

replace deputy_hoursdir = . if deputy_hoursdir==0 & deputy_hoursteach==0
replace deputy_hoursteach = . if deputy_hoursdir==. & deputy_hoursteach==0

replace date_day = . if date_day==99
replace date_month = . if date_month==99
replace date_year = 2017


****************************************
************** QUADRO1A ****************
****************************************

forval x=5/14{
lab var tot_mf_`x'_1 "Number of students pre-school age `x'"
lab var tot_mf_`x'_2 "Number of students grade 1 age `x'"
lab var tot_mf_`x'_3 "Number of students grade 2 age `x'"
lab var tot_mf_`x'_4 "Number of students grade 3 age `x'"
lab var tot_mf_`x'_5 "Number of students grade 4 age `x'"
lab var tot_mf_`x'_6 "Number of students grade 5 age `x'"
lab var tot_mf_`x'_7 "Number of students grade 6 age `x'"

lab var tot_f_`x'_1 "Number of girls pre-school age `x'"
lab var tot_f_`x'_2 "Number of girls grade 1 age `x'"
lab var tot_f_`x'_3 "Number of girls grade 2 age `x'"
lab var tot_f_`x'_4 "Number of girls grade 3 age `x'"
lab var tot_f_`x'_5 "Number of girls grade 4 age `x'"
lab var tot_f_`x'_6 "Number of girls grade 5 age `x'"
lab var tot_f_`x'_7 "Number of girls grade 6 age `x'"
}

rename tot_mf_(#)_1 students_pre_age(#)
rename tot_mf_(#)_2 students_g1_age(#)
rename tot_mf_(#)_3 students_g2_age(#)
rename tot_mf_(#)_4 students_g3_age(#)
rename tot_mf_(#)_5 students_g4_age(#)
rename tot_mf_(#)_6 students_g5_age(#)
rename tot_mf_(#)_7 students_g6_age(#)

rename tot_mf_(##)_1 students_pre_age(##)
rename tot_mf_(##)_2 students_g1_age(##)
rename tot_mf_(##)_3 students_g2_age(##)
rename tot_mf_(##)_4 students_g3_age(##)
rename tot_mf_(##)_5 students_g4_age(##)
rename tot_mf_(##)_6 students_g5_age(##)
rename tot_mf_(##)_7 students_g6_age(##)

rename tot_f_(#)_1 girls_pre_age(#)
rename tot_f_(#)_2 girls_g1_age(#)
rename tot_f_(#)_3 girls_g2_age(#)
rename tot_f_(#)_4 girls_g3_age(#)
rename tot_f_(#)_5 girls_g4_age(#)
rename tot_f_(#)_6 girls_g5_age(#)
rename tot_f_(#)_7 girls_g6_age(#)

rename tot_f_(##)_1 girls_pre_age(##)
rename tot_f_(##)_2 girls_g1_age(##)
rename tot_f_(##)_3 girls_g2_age(##)
rename tot_f_(##)_4 girls_g3_age(##)
rename tot_f_(##)_5 girls_g4_age(##)
rename tot_f_(##)_6 girls_g5_age(##)
rename tot_f_(##)_7 girls_g6_age(##)

egen students_pre = rowtotal(students_pre_age5 students_pre_age6 students_pre_age7 students_pre_age8 students_pre_age9 students_pre_age10 students_pre_age11 students_pre_age12 students_pre_age13 students_pre_age14), missing
egen girls_pre = rowtotal(girls_pre_age5 girls_pre_age6 girls_pre_age7 girls_pre_age8 girls_pre_age9 girls_pre_age10 girls_pre_age11 girls_pre_age12 girls_pre_age13 girls_pre_age14), missing

forval x=1/6{
egen students_g`x' = rowtotal(students_g`x'_age5 students_g`x'_age6 students_g`x'_age7 students_g`x'_age8 students_g`x'_age9 students_g`x'_age10 students_g`x'_age11 students_g`x'_age12 students_g`x'_age13 students_g`x'_age14), missing
egen girls_g`x' = rowtotal(girls_g`x'_age5 girls_g`x'_age6 girls_g`x'_age7 girls_g`x'_age8 girls_g`x'_age9 girls_g`x'_age10 girls_g`x'_age11 girls_g`x'_age12 girls_g`x'_age13 girls_g`x'_age14), missing
}

egen students = rowtotal(students_pre students_g1 students_g2 students_g3 students_g4 students_g5 students_g6)
egen girls = rowtotal(girls_pre girls_g1 girls_g2 girls_g3 girls_g4 girls_g5 girls_g6)



lab var students_pre 	"Number of students in pre-school"
lab var girls_pre  		"Number of girls in pre-school"
lab var students_g1  	"Number of students in grade 1"
lab var girls_g1  		"Number of girls in grade 1"
lab var students_g2  	"Number of students in grade 2"
lab var girls_g2  		"Number of girls in grade 2"
lab var students_g3  	"Number of students in grade 3"
lab var girls_g3  		"Number of girls in grade 3"
lab var students_g4 	"Number of students in grade 4"
lab var girls_g4  		"Number of girls in grade 4"
lab var students_g5  	"Number of students in grade 5"
lab var girls_g5  		"Number of girls in grade 5"
lab var students_g6  	"Number of students in grade 6"
lab var girls_g6  		"Number of girls in grade 6"
lab var students  		"Number of students in total"
lab var girls 			"Number of girls in total"


order students_pre girls_pre students_g1 girls_g1 students_g2 girls_g2 students_g3 girls_g3 students_g4 girls_g4 students_g5 girls_g5 students_g6 girls_g6 students girls, after(girls_g6_age14)

****************************************
************** QUADRO1B ****************
****************************************


forval x=5/14{
lab var rep_mf_`x'_1 "Number of repeaters pre-school age `x'"
lab var rep_mf_`x'_2 "Number of repeaters grade 1 age `x'"
lab var rep_mf_`x'_3 "Number of repeaters grade 2 age `x'"
lab var rep_mf_`x'_4 "Number of repeaters grade 3 age `x'"
lab var rep_mf_`x'_5 "Number of repeaters grade 4 age `x'"
lab var rep_mf_`x'_6 "Number of repeaters grade 5 age `x'"
lab var rep_mf_`x'_7 "Number of repeaters grade 6 age `x'"

lab var rep_f_`x'_1 "Number of repeaters (girls) pre-school age `x'"
lab var rep_f_`x'_2 "Number of repeaters (girls) grade 1 age `x'"
lab var rep_f_`x'_3 "Number of repeaters (girls) grade 2 age `x'"
lab var rep_f_`x'_4 "Number of repeaters (girls) grade 3 age `x'"
lab var rep_f_`x'_5 "Number of repeaters (girls) grade 4 age `x'"
lab var rep_f_`x'_6 "Number of repeaters (girls) grade 5 age `x'"
lab var rep_f_`x'_7 "Number of repeaters (girls) grade 6 age `x'"
}

rename rep_mf_(#)_1 repeaters_pre_age(#)
rename rep_mf_(#)_2 repeaters_g1_age(#)
rename rep_mf_(#)_3 repeaters_g2_age(#)
rename rep_mf_(#)_4 repeaters_g3_age(#)
rename rep_mf_(#)_5 repeaters_g4_age(#)
rename rep_mf_(#)_6 repeaters_g5_age(#)
rename rep_mf_(#)_7 repeaters_g6_age(#)

rename rep_mf_(##)_1 repeaters_pre_age(##)
rename rep_mf_(##)_2 repeaters_g1_age(##)
rename rep_mf_(##)_3 repeaters_g2_age(##)
rename rep_mf_(##)_4 repeaters_g3_age(##)
rename rep_mf_(##)_5 repeaters_g4_age(##)
rename rep_mf_(##)_6 repeaters_g5_age(##)
rename rep_mf_(##)_7 repeaters_g6_age(##)

rename rep_f_(#)_1 repeatgirl_pre_age(#)
rename rep_f_(#)_2 repeatgirl_g1_age(#)
rename rep_f_(#)_3 repeatgirl_g2_age(#)
rename rep_f_(#)_4 repeatgirl_g3_age(#)
rename rep_f_(#)_5 repeatgirl_g4_age(#)
rename rep_f_(#)_6 repeatgirl_g5_age(#)
rename rep_f_(#)_7 repeatgirl_g6_age(#)

rename rep_f_(##)_1 repeatgirl_pre_age(##)
rename rep_f_(##)_2 repeatgirl_g1_age(##)
rename rep_f_(##)_3 repeatgirl_g2_age(##)
rename rep_f_(##)_4 repeatgirl_g3_age(##)
rename rep_f_(##)_5 repeatgirl_g4_age(##)
rename rep_f_(##)_6 repeatgirl_g5_age(##)
rename rep_f_(##)_7 repeatgirl_g6_age(##)

egen repeaters_pre = rowtotal(repeaters_pre_age5 repeaters_pre_age6 repeaters_pre_age7 repeaters_pre_age8 repeaters_pre_age9 repeaters_pre_age10 repeaters_pre_age11 repeaters_pre_age12 repeaters_pre_age13 repeaters_pre_age14), missing
egen repeatgirl_pre = rowtotal(repeatgirl_pre_age5 repeatgirl_pre_age6 repeatgirl_pre_age7 repeatgirl_pre_age8 repeatgirl_pre_age9 repeatgirl_pre_age10 repeatgirl_pre_age11 repeatgirl_pre_age12 repeatgirl_pre_age13 repeatgirl_pre_age14), missing

forval x=1/6{
egen repeaters_g`x' = rowtotal(repeaters_g`x'_age5 repeaters_g`x'_age6 repeaters_g`x'_age7 repeaters_g`x'_age8 repeaters_g`x'_age9 repeaters_g`x'_age10 repeaters_g`x'_age11 repeaters_g`x'_age12 repeaters_g`x'_age13 repeaters_g`x'_age14), missing
egen repeatgirl_g`x' = rowtotal(repeatgirl_g`x'_age5 repeatgirl_g`x'_age6 repeatgirl_g`x'_age7 repeatgirl_g`x'_age8 repeatgirl_g`x'_age9 repeatgirl_g`x'_age10 repeatgirl_g`x'_age11 repeatgirl_g`x'_age12 repeatgirl_g`x'_age13 repeatgirl_g`x'_age14), missing
}

egen repeaters = rowtotal(repeaters_pre repeaters_g1 repeaters_g2 repeaters_g3 repeaters_g4 repeaters_g5 repeaters_g6)
egen repeatgirl = rowtotal(repeatgirl_pre repeatgirl_g1 repeatgirl_g2 repeatgirl_g3 repeatgirl_g4 repeatgirl_g5 repeatgirl_g6)

lab var repeaters_pre 	"Number of repeaters in pre-school"
lab var repeatgirl_pre  "Number of repeating girls in pre-school"
lab var repeaters_g1  	"Number of repeaters in grade 1"
lab var repeatgirl_g1  	"Number of repeating girls in grade 1"
lab var repeaters_g2  	"Number of repeaters in grade 2"
lab var repeatgirl_g2  	"Number of repeating girls in grade 2"
lab var repeaters_g3  	"Number of repeaters in grade 3"
lab var repeatgirl_g3  	"Number of repeating girls in grade 3"
lab var repeaters_g4 	"Number of repeaters in grade 4"
lab var repeatgirl_g4  	"Number of repeating girls in grade 4"
lab var repeaters_g5  	"Number of repeaters in grade 5"
lab var repeatgirl_g5  	"Number of repeating girls in grade 5"
lab var repeaters_g6  	"Number of repeaters in grade 6"
lab var repeatgirl_g6  	"Number of repeating girls in grade 6"
lab var repeaters  		"Number of repeaters in total"
lab var repeatgirl 		"Number of repeating girls in total"

order repeaters_pre repeatgirl_pre repeaters_g1 repeatgirl_g1 repeaters_g2 repeatgirl_g2 repeaters_g3 repeatgirl_g3 repeaters_g4 repeatgirl_g4 repeaters_g5 repeatgirl_g5 repeaters_g6 repeatgirl_g6 repeaters repeatgirl ,after(repeatgirl_g6_age14)

****************************************
************** QUADRO2 *****************
****************************************

label variable n_de_turmas_1 "Number of pre-school classes"
label variable n_de_turmas_2 "Number of 1st grade classes"
label variable n_de_turmas_3 "Number of 2nd grade classes"
label variable n_de_turmas_4 "Number of 3rd grade classes"
label variable n_de_turmas_5 "Number of 4th grade classes"
label variable n_de_turmas_6 "Number of 5th grade classes"
label variable n_de_turmas_7 "Number of 6th grade classes"

label variable n_de_turnos_1 "Number periods the pre-school classes or divided over"
label variable n_de_turnos_2 "Number periods the 1st grade classes or divided over"
label variable n_de_turnos_3 "Number periods the 2nd grade classes or divided over"
label variable n_de_turnos_4 "Number periods the 3rd grade classes or divided over"
label variable n_de_turnos_5 "Number periods the 4th grade classes or divided over"
label variable n_de_turnos_6 "Number periods the 5th grade classes or divided over"
label variable n_de_turnos_7 "Number periods the 6th grade classes or divided over"

rename n_de_turmas_1 		classes_pre
rename n_de_turmas_2 		classes_g1
rename n_de_turmas_3  		classes_g2
rename n_de_turmas_4   		classes_g3
rename n_de_turmas_5   		classes_g4
rename n_de_turmas_6   		classes_g5
rename n_de_turmas_7   		classes_g6

rename n_de_turnos_1   		periods_pre
rename n_de_turnos_2    	periods_g1
rename n_de_turnos_3    	periods_g2
rename n_de_turnos_4    	periods_g3
rename n_de_turnos_5    	periods_g4
rename n_de_turnos_6    	periods_g5
rename n_de_turnos_7   		periods_g6

egen classes = rowtotal(classes_pre classes_g1 classes_g2 classes_g3 classes_g4 classes_g5 classes_g6), missing

lab var classes "Number of classes in total"

order classes ,after(classes_g6)

****************************************
************** QUADRO3 *****************
****************************************


label variable nec_mf_vis_1 "Number of students with visual disability in pre-school"
label variable nec_mf_vis_2 "Number of students with visual disability in grade 1"
label variable nec_mf_vis_3 "Number of students with visual disability in grade 2"
label variable nec_mf_vis_4 "Number of students with visual disability in grade 3"
label variable nec_mf_vis_5 "Number of students with visual disability in grade 4"
label variable nec_mf_vis_6 "Number of students with visual disability in grade 5"
label variable nec_mf_vis_7 "Number of students with visual disability in grade 6"

label variable nec_f_vis_1 "Number of girls with visual disability in pre-school"
label variable nec_f_vis_2 "Number of girls with visual disability in grade 1"
label variable nec_f_vis_3 "Number of girls with visual disability in grade 2"
label variable nec_f_vis_4 "Number of girls with visual disability in grade 3"
label variable nec_f_vis_5 "Number of girls with visual disability in grade 4"
label variable nec_f_vis_6 "Number of girls with visual disability in grade 5"
label variable nec_f_vis_7 "Number of girls with visual disability in grade 6"

label variable nec_mf_aud_1 "Number of students with auditory disability in pre-school"
label variable nec_mf_aud_2 "Number of students with auditory disability in grade 1"
label variable nec_mf_aud_3 "Number of students with auditory disability in grade 2"
label variable nec_mf_aud_4 "Number of students with auditory disability in grade 3"
label variable nec_mf_aud_5 "Number of students with auditory disability in grade 4"
label variable nec_mf_aud_6 "Number of students with auditory disability in grade 5"
label variable nec_mf_aud_7 "Number of students with auditory disability in grade 6"

label variable nec_f_aud_1 "Number of girls with auditory disability in pre-school"
label variable nec_f_aud_2 "Number of girls with auditory disability in grade 1"
label variable nec_f_aud_3 "Number of girls with auditory disability in grade 2"
label variable nec_f_aud_4 "Number of girls with auditory disability in grade 3"
label variable nec_f_aud_5 "Number of girls with auditory disability in grade 4"
label variable nec_f_aud_6 "Number of girls with auditory disability in grade 5"
label variable nec_f_aud_7 "Number of girls with auditory disability in grade 6"

label variable nec_mf_mot_1 "Number of students with motor disability in pre-school"
label variable nec_mf_mot_2 "Number of students with motor disability in grade 1"
label variable nec_mf_mot_3 "Number of students with motor disability in grade 2"
label variable nec_mf_mot_4 "Number of students with motor disability in grade 3"
label variable nec_mf_mot_5 "Number of students with motor disability in grade 4"
label variable nec_mf_mot_6 "Number of students with motor disability in grade 5"
label variable nec_mf_mot_7 "Number of students with motor disability in grade 6"

label variable nec_f_mot_1 "Number of girls with motor disability in pre-school"
label variable nec_f_mot_2 "Number of girls with motor disability in grade 1"
label variable nec_f_mot_3 "Number of girls with motor disability in grade 2"
label variable nec_f_mot_4 "Number of girls with motor disability in grade 3"
label variable nec_f_mot_5 "Number of girls with motor disability in grade 4"
label variable nec_f_mot_6 "Number of girls with motor disability in grade 5"
label variable nec_f_mot_7 "Number of girls with motor disability in grade 6"

label variable nec_mf_out_1 "Number of students with other disability in pre-school"
label variable nec_mf_out_2 "Number of students with other disability in grade 1"
label variable nec_mf_out_3 "Number of students with other disability in grade 2"
label variable nec_mf_out_4 "Number of students with other disability in grade 3"
label variable nec_mf_out_5 "Number of students with other disability in grade 4"
label variable nec_mf_out_6 "Number of students with other disability in grade 5"
label variable nec_mf_out_7 "Number of students with other disability in grade 6"

label variable nec_f_out_1 "Number of girls with other disability in pre-school"
label variable nec_f_out_2 "Number of girls with other disability in grade 1"
label variable nec_f_out_3 "Number of girls with other disability in grade 2"
label variable nec_f_out_4 "Number of girls with other disability in grade 3"
label variable nec_f_out_5 "Number of girls with other disability in grade 4"
label variable nec_f_out_6 "Number of girls with other disability in grade 5"
label variable nec_f_out_7 "Number of girls with other disability in grade 6"

rename nec_mf_vis_1 	disabled_visual_pre
rename nec_mf_vis_2  	disabled_visual_g1
rename nec_mf_vis_3  	disabled_visual_g2
rename nec_mf_vis_4  	disabled_visual_g3
rename nec_mf_vis_5  	disabled_visual_g4
rename nec_mf_vis_6  	disabled_visual_g5
rename nec_mf_vis_7  	disabled_visual_g6

rename nec_f_vis_1  	disabgirl_visual_pre
rename nec_f_vis_2  	disabgirl_visual_g1
rename nec_f_vis_3  	disabgirl_visual_g2
rename nec_f_vis_4  	disabgirl_visual_g3
rename nec_f_vis_5  	disabgirl_visual_g4
rename nec_f_vis_6  	disabgirl_visual_g5
rename nec_f_vis_7  	disabgirl_visual_g6

rename nec_mf_aud_1  	disabled_audio_pre
rename nec_mf_aud_2  	disabled_audio_g1
rename nec_mf_aud_3  	disabled_audio_g2
rename nec_mf_aud_4  	disabled_audio_g3
rename nec_mf_aud_5  	disabled_audio_g4
rename nec_mf_aud_6  	disabled_audio_g5
rename nec_mf_aud_7  	disabled_audio_g6

rename nec_f_aud_1  	disabgirl_audio_pre
rename nec_f_aud_2  	disabgirl_audio_g1
rename nec_f_aud_3  	disabgirl_audio_g2
rename nec_f_aud_4  	disabgirl_audio_g3
rename nec_f_aud_5  	disabgirl_audio_g4
rename nec_f_aud_6  	disabgirl_audio_g5
rename nec_f_aud_7  	disabgirl_audio_g6

rename nec_mf_mot_1  	disabled_motor_pre
rename nec_mf_mot_2  	disabled_motor_g1
rename nec_mf_mot_3  	disabled_motor_g2
rename nec_mf_mot_4  	disabled_motor_g3
rename nec_mf_mot_5  	disabled_motor_g4
rename nec_mf_mot_6  	disabled_motor_g5
rename nec_mf_mot_7  	disabled_motor_g6

rename nec_f_mot_1  	disabgirl_motor_pre
rename nec_f_mot_2  	disabgirl_motor_g1
rename nec_f_mot_3  	disabgirl_motor_g2
rename nec_f_mot_4  	disabgirl_motor_g3
rename nec_f_mot_5  	disabgirl_motor_g4
rename nec_f_mot_6  	disabgirl_motor_g5
rename nec_f_mot_7  	disabgirl_motor_g6

rename nec_mf_out_1  	disabled_other_pre
rename nec_mf_out_2  	disabled_other_g1
rename nec_mf_out_3  	disabled_other_g2
rename nec_mf_out_4  	disabled_other_g3
rename nec_mf_out_5  	disabled_other_g4
rename nec_mf_out_6  	disabled_other_g5
rename nec_mf_out_7  	disabled_other_g6

rename nec_f_out_1  	disabgirl_other_pre
rename nec_f_out_2  	disabgirl_other_g1
rename nec_f_out_3  	disabgirl_other_g2
rename nec_f_out_4  	disabgirl_other_g3
rename nec_f_out_5  	disabgirl_other_g4
rename nec_f_out_6  	disabgirl_other_g5
rename nec_f_out_7 		disabgirl_other_g6

egen disabled_pre = rowtotal(disabled_visual_pre disabled_audio_pre disabled_motor_pre disabled_other_pre), missing
egen disabgirl_pre = rowtotal(disabgirl_visual_pre disabgirl_audio_pre disabgirl_motor_pre disabgirl_other_pre), missing


forval x=1/6{
egen disabled_g`x' = rowtotal(disabled_visual_g`x' disabled_audio_g`x' disabled_motor_g`x' disabled_other_g`x'), missing
egen disabgirl_g`x' = rowtotal(disabgirl_visual_g`x' disabgirl_audio_g`x' disabgirl_motor_g`x' disabgirl_other_g`x'), missing
}

egen disabled_visual = rowtotal(disabled_visual_pre disabled_visual_g1 disabled_visual_g2 disabled_visual_g3 disabled_visual_g4 disabled_visual_g5 disabled_visual_g6), missing
egen disabgirl_visual = rowtotal(disabgirl_visual_pre disabgirl_visual_g1 disabgirl_visual_g2 disabgirl_visual_g3 disabgirl_visual_g4 disabgirl_visual_g5 disabgirl_visual_g6), missing

egen disabled_audio = rowtotal(disabled_audio_pre disabled_audio_g1 disabled_audio_g2 disabled_audio_g3 disabled_audio_g4 disabled_audio_g5 disabled_audio_g6), missing
egen disabgirl_audio = rowtotal(disabgirl_audio_pre disabgirl_audio_g1 disabgirl_audio_g2 disabgirl_audio_g3 disabgirl_audio_g4 disabgirl_audio_g5 disabgirl_audio_g6), missing

egen disabled_motor = rowtotal(disabled_motor_pre disabled_motor_g1 disabled_motor_g2 disabled_motor_g3 disabled_motor_g4 disabled_motor_g5 disabled_motor_g6), missing
egen disabgirl_motor = rowtotal(disabgirl_motor_pre disabgirl_motor_g1 disabgirl_motor_g2 disabgirl_motor_g3 disabgirl_motor_g4 disabgirl_motor_g5 disabgirl_motor_g6), missing

egen disabled_other = rowtotal(disabled_other_pre disabled_other_g1 disabled_other_g2 disabled_other_g3 disabled_other_g4 disabled_other_g5 disabled_other_g6), missing
egen disabgirl_other = rowtotal(disabgirl_other_pre disabgirl_other_g1 disabgirl_other_g2 disabgirl_other_g3 disabgirl_other_g4 disabgirl_other_g5 disabgirl_other_g6), missing

egen disabled = rowtotal(disabled_visual disabled_audio disabled_motor disabled_other), missing
egen disabgirl = rowtotal(disabgirl_visual disabgirl_audio disabgirl_motor disabgirl_other), missing

order disabled_pre disabgirl_pre disabled_g1 disabgirl_g1 disabled_g2 disabgirl_g2 disabled_g3 disabgirl_g3 disabled_g4 disabgirl_g4 disabled_g5 disabgirl_g5 disabled_g6 disabgirl_g6 disabled_visual disabgirl_visual disabled_audio disabgirl_audio disabled_motor disabgirl_motor disabled_other disabgirl_other disabled disabgirl, after(disabgirl_other_g6)

lab var disabled_pre 		"Number of disabled students in pre-school"
lab var disabgirl_pre 	 	"Number of disabled girls in pre-school"
lab var disabled_g1  		"Number of disabled students in grade 1"
lab var disabgirl_g1  		"Number of disabled girls in grade 1"
lab var disabled_g2  		"Number of disabled students in grade 2"
lab var disabgirl_g2  		"Number of disabled girls in grade 2"
lab var disabled_g3  		"Number of disabled students in grade 3"
lab var disabgirl_g3  		"Number of disabled girls in grade 3"
lab var disabled_g4 		"Number of disabled students in grade 4"
lab var disabgirl_g4  		"Number of disabled girls in grade 4"
lab var disabled_g5  		"Number of disabled students in grade 5"
lab var disabgirl_g5  		"Number of disabled girls in grade 5"
lab var disabled_g6  		"Number of disabled students in grade 6"
lab var disabgirl_g6  		"Number of disabled girls in grade 6"
lab var disabled  			"Number of disabled students in total"
lab var disabgirl 			"Number of disabled girls in total"

lab var disabled_visual 	"Number of students with visual disability"
lab var disabgirl_visual  	"Number of girls with visual disability"
lab var disabled_audio  	"Number of students with auditory disability"
lab var disabgirl_audio  	"Number of girls with auditory disability"
lab var disabled_motor  	"Number of students with motor disability"
lab var disabgirl_motor  	"Number of girls with motor disability"
lab var disabled_other  	"Number of students with other disability"
lab var disabgirl_other 	"Number of girls with other disability"

****************************************
************** QUADRO4 *****************
****************************************

label variable nivprof_mf_6_ini_1 "Pre-school teachers education: until grade 6 with pedagocial training"
label variable nivprof_mf_6_ini_2 "Pre-school teachers education: until grade 6 without pedagocial training"
label variable nivprof_f_6_ini_1 "Pre-school female teachers education: until grade 6 with pedagocial training"
label variable nivprof_f_6_ini_2 "Pre-school female teachers education: until grade 6 without pedagocial training"

label variable nivprof_mf_9_ini_1 "Pre-school teachers education: grade 7-9 with pedagocial training"
label variable nivprof_mf_9_ini_2 "Pre-school teachers education: grade 7-9  without pedagocial training"
label variable nivprof_f_9_ini_1 "Pre-school female teachers education: grade 7-9  with pedagocial training"
label variable nivprof_f_9_ini_2 "Pre-school female teachers education: grade 7-9  without pedagocial training"

label variable nivprof_mf_11_ini_1 "Pre-school teachers education: grade 10-11 with pedagocial training"
label variable nivprof_mf_11_ini_2 "Pre-school teachers education: grade 10-11  without pedagocial training"
label variable nivprof_f_11_ini_1 "Pre-school female teachers education: grade 10-11  with pedagocial training"
label variable nivprof_f_11_ini_2 "Pre-school female teachers education: grade 10-11  without pedagocial training"

label variable nivprof_mf_13_ini_1 "Pre-school teachers education: grade 12-13 with pedagocial training"
label variable nivprof_mf_13_ini_2 "Pre-school teachers education: grade 12-13  without pedagocial training"
label variable nivprof_f_13_ini_1 "Pre-school female teachers education: grade 12-13  with pedagocial training"
label variable nivprof_f_13_ini_2 "Pre-school female teachers education: grade 12-13  without pedagocial training"

label variable nivprof_mf_bach_ini_1 "Pre-school teachers education: bachelor with pedagocial training"
label variable nivprof_mf_bach_ini_2 "Pre-school teachers education: bachelor  without pedagocial training"
label variable nivprof_f_bach_ini_1 "Pre-school female teachers education: bachelor  with pedagocial training"
label variable nivprof_f_bach_ini_2 "Pre-school female teachers education: bachelor  without pedagocial training"

label variable nivprof_mf_lic_ini_1 "Pre-school teachers education: graduated or more with pedagocial training"
label variable nivprof_mf_lic_ini_2 "Pre-school teachers education: graduated or more  without pedagocial training"
label variable nivprof_f_lic_ini_1 "Pre-school female teachers education: graduated or more  with pedagocial training"
label variable nivprof_f_lic_ini_2 "Pre-school female teachers education: graduated or more  without pedagocial training"


label variable nivprof_mf_6_1 "Primary school teachers education: until grade 6 with pedagocial training"
label variable nivprof_mf_6_2 "Primary school teachers education: until grade 6 without pedagocial training"
label variable nivprof_f_6_1 "Primary school female teachers education: until grade 6 with pedagocial training"
label variable nivprof_f_6_2 "Primary school female teachers education: until grade 6 without pedagocial training"

label variable nivprof_mf_9_1 "Primary school teachers education: grade 7-9 with pedagocial training"
label variable nivprof_mf_9_2 "Primary school teachers education: grade 7-9 without pedagocial training"
label variable nivprof_f_9_1 "Primary school female teachers education: grade 7-9 with pedagocial training"
label variable nivprof_f_9_2 "Primary school female teachers education: grade 7-9 without pedagocial training"

label variable nivprof_mf_11_1 "Primary school teachers education: grade 10-11 with pedagocial training"
label variable nivprof_mf_11_2 "Primary school teachers education: grade 10-11 without pedagocial training"
label variable nivprof_f_11_1 "Primary school female teachers education: grade 10-11 with pedagocial training"
label variable nivprof_f_11_2 "Primary school female teachers education: grade 10-11 without pedagocial training"

label variable nivprof_mf_13_1 "Primary school teachers education: grade 12-13 with pedagocial training"
label variable nivprof_mf_13_2 "Primary school teachers education: grade 12-13 without pedagocial training"
label variable nivprof_f_13_1 "Primary school female teachers education: grade 12-13 with pedagocial training"
label variable nivprof_f_13_2 "Primary school female teachers education: grade 12-13 without pedagocial training"

label variable nivprof_mf_bach_1 "Primary school teachers education: bachelor with pedagocial training"
label variable nivprof_mf_bach_2 "Primary school teachers education: bachelor without pedagocial training"
label variable nivprof_f_bach_1 "Primary school female teachers education: bachelor with pedagocial training"
label variable nivprof_f_bach_2 "Primary school female teachers education: bachelor without pedagocial training"

label variable nivprof_mf_lic_1 "Primary school teachers education: graduated or more with pedagocial training"
label variable nivprof_mf_lic_2 "Primary school teachers education: graduated or more  without pedagocial training"
label variable nivprof_f_lic_1 "Primary school female teachers education: graduated or more  with pedagocial training"
label variable nivprof_f_lic_2 "Primary school female teachers education: graduated or more  without pedagocial training"


foreach var in nivprof_mf_6_ini_1 nivprof_mf_6_ini_2 nivprof_f_6_ini_1 nivprof_f_6_ini_2 nivprof_mf_9_ini_1 nivprof_mf_9_ini_2 nivprof_f_9_ini_1 nivprof_f_9_ini_2 nivprof_mf_11_ini_1 nivprof_mf_11_ini_2 nivprof_f_11_ini_1 nivprof_f_11_ini_2 nivprof_mf_13_ini_1 nivprof_mf_13_ini_2 nivprof_f_13_ini_1 nivprof_f_13_ini_2 nivprof_mf_bach_ini_1 nivprof_mf_bach_ini_2 nivprof_f_bach_ini_1 nivprof_f_bach_ini_2 nivprof_mf_lic_ini_1 nivprof_mf_lic_ini_2 nivprof_f_lic_ini_1 nivprof_f_lic_ini_2 nivprof_mf_6_1 nivprof_mf_6_2 nivprof_f_6_1 nivprof_f_6_2 nivprof_mf_9_1 nivprof_mf_9_2 nivprof_f_9_1 nivprof_f_9_2 nivprof_mf_11_1 nivprof_mf_11_2 nivprof_f_11_1 nivprof_f_11_2 nivprof_mf_13_1 nivprof_mf_13_2 nivprof_f_13_1 nivprof_f_13_2 nivprof_mf_bach_1 nivprof_mf_bach_2 nivprof_f_bach_1 nivprof_f_bach_2 nivprof_mf_lic_1 nivprof_mf_lic_2 nivprof_f_lic_1 nivprof_f_lic_2{
replace `var' = . if `var'==99
}

rename nivprof_mf_9_ini_1 	nivprof_mf_7_ini_1
rename nivprof_mf_9_ini_2  	nivprof_mf_7_ini_2
rename nivprof_f_9_ini_1  	nivprof_f_7_ini_1
rename nivprof_f_9_ini_2  	nivprof_f_7_ini_2
rename nivprof_mf_11_ini_1  nivprof_mf_10_ini_1
rename nivprof_mf_11_ini_2  nivprof_mf_10_ini_2
rename nivprof_f_11_ini_1  	nivprof_f_10_ini_1
rename nivprof_f_11_ini_2  	nivprof_f_10_ini_2
rename nivprof_mf_13_ini_1  nivprof_mf_12_ini_1
rename nivprof_mf_13_ini_2  nivprof_mf_12_ini_2
rename nivprof_f_13_ini_1  	nivprof_f_12_ini_1
rename nivprof_f_13_ini_2  	nivprof_f_12_ini_2
rename nivprof_mf_9_1  		nivprof_mf_7_1
rename nivprof_mf_9_2  		nivprof_mf_7_2
rename nivprof_f_9_1  		nivprof_f_7_1
rename nivprof_f_9_2  		nivprof_f_7_2
rename nivprof_mf_11_1  	nivprof_mf_10_1
rename nivprof_mf_11_2  	nivprof_mf_10_2
rename nivprof_f_11_1  		nivprof_f_10_1
rename nivprof_f_11_2  		nivprof_f_10_2
rename nivprof_mf_13_1  	nivprof_mf_12_1
rename nivprof_mf_13_2  	nivprof_mf_12_2
rename nivprof_f_13_1  		nivprof_f_12_1
rename nivprof_f_13_2		nivprof_f_12_2

replace nivprof_mf_6_ini_1 = 0 if school_id==37
replace nivprof_mf_6_ini_2 = 0 if school_id==37
replace nivprof_f_6_ini_1 = 0 if school_id==37
replace nivprof_f_6_ini_2 = 0 if school_id==37
replace nivprof_mf_7_ini_1 = 0 if school_id==37
replace nivprof_mf_7_ini_2 = 0 if school_id==37
replace nivprof_f_7_ini_1 = 0 if school_id==37
replace nivprof_f_7_ini_2 = 0 if school_id==37
replace nivprof_mf_10_ini_1 = 0 if school_id==37
replace nivprof_mf_10_ini_2 = 0 if school_id==37
replace nivprof_f_10_ini_1 = 0 if school_id==37
replace nivprof_f_10_ini_2 = 0 if school_id==37
replace nivprof_mf_12_ini_1 = 0 if school_id==37
replace nivprof_mf_12_ini_2 = 0 if school_id==37
replace nivprof_f_12_ini_1 = 0 if school_id==37
replace nivprof_f_12_ini_2 = 0 if school_id==37
replace nivprof_mf_bach_ini_1 = 0 if school_id==37
replace nivprof_mf_bach_ini_2 = 0 if school_id==37
replace nivprof_f_bach_ini_1 = 0 if school_id==37
replace nivprof_f_bach_ini_2 = 0 if school_id==37
replace nivprof_mf_lic_ini_1 = 0 if school_id==37
replace nivprof_mf_lic_ini_2 = 0 if school_id==37
replace nivprof_f_lic_ini_1 = 0 if school_id==37
replace nivprof_f_lic_ini_2 = 0 if school_id==37
replace nivprof_mf_6_1 = 0 if school_id==37
replace nivprof_mf_6_2 = 0 if school_id==37
replace nivprof_f_6_1 = 0 if school_id==37
replace nivprof_f_6_2 = 0 if school_id==37
replace nivprof_mf_7_1 = 4 if school_id==37
replace nivprof_mf_7_2 = 0 if school_id==37
replace nivprof_f_7_1 = 1 if school_id==37
replace nivprof_f_7_2 = 0 if school_id==37
replace nivprof_mf_10_1 = 3 if school_id==37
replace nivprof_mf_10_2 = 0 if school_id==37
replace nivprof_f_10_1 = 3 if school_id==37
replace nivprof_f_10_2 = 0 if school_id==37
replace nivprof_mf_12_1 = 0 if school_id==37
replace nivprof_mf_12_2 = 0 if school_id==37
replace nivprof_f_12_1 = 0 if school_id==37
replace nivprof_f_12_2 = 0 if school_id==37
replace nivprof_mf_bach_1 = 0 if school_id==37
replace nivprof_mf_bach_2 = 0 if school_id==37
replace nivprof_f_bach_1 = 0 if school_id==37
replace nivprof_f_bach_2 = 0 if school_id==37
replace nivprof_mf_lic_1 = 0 if school_id==37
replace nivprof_mf_lic_2 = 0 if school_id==37
replace nivprof_f_lic_1 = 0 if school_id==37
replace nivprof_f_lic_2 = 0 if school_id==37


egen teachers_pre_until13 = rowtotal(nivprof_mf_6_ini_1 nivprof_mf_6_ini_2 nivprof_mf_7_ini_1 nivprof_mf_7_ini_2 nivprof_mf_10_ini_1 nivprof_mf_10_ini_2 nivprof_mf_12_ini_1 nivprof_mf_12_ini_2), missing
egen teachfem_pre_until13 = rowtotal(nivprof_f_6_ini_1 nivprof_f_6_ini_2 nivprof_f_7_ini_1 nivprof_f_7_ini_2 nivprof_f_10_ini_1 nivprof_f_10_ini_2 nivprof_f_12_ini_1 nivprof_f_12_ini_2), missing

egen teachers_pre_uni = rowtotal(nivprof_mf_bach_ini_1 nivprof_mf_bach_ini_2 nivprof_mf_lic_ini_1 nivprof_mf_lic_ini_2), missing
egen teachfem_pre_uni = rowtotal(nivprof_f_bach_ini_1 nivprof_f_bach_ini_2 nivprof_f_lic_ini_1 nivprof_f_lic_ini_2), missing

egen teachers_pre2 = rowtotal(teachers_pre_until13 teachers_pre_uni), missing
egen teachfem_pre2 = rowtotal(teachfem_pre_until13 teachfem_pre_uni), missing

egen teachers_prim_until13 = rowtotal(nivprof_mf_6_1 nivprof_mf_6_2 nivprof_mf_7_1 nivprof_mf_7_2 nivprof_mf_10_1 nivprof_mf_10_2 nivprof_mf_12_1 nivprof_mf_12_2), missing
egen teachfem_prim_until13 = rowtotal(nivprof_f_6_1 nivprof_f_6_2 nivprof_f_7_1 nivprof_f_7_2 nivprof_f_10_1 nivprof_f_10_2 nivprof_f_12_1 nivprof_f_12_2), missing

egen teachers_prim_uni = rowtotal(nivprof_mf_bach_1 nivprof_mf_bach_2 nivprof_mf_lic_1 nivprof_mf_lic_2), missing
egen teachfem_prim_uni = rowtotal(nivprof_f_bach_1 nivprof_f_bach_2 nivprof_f_lic_1 nivprof_f_lic_2), missing

egen teachers_prim2 = rowtotal(teachers_prim_until13 teachers_prim_uni), missing
egen teachfem_prim2 = rowtotal(teachfem_prim_until13 teachfem_prim_uni), missing

egen teachers_uni = rowtotal(teachers_pre_uni teachers_prim_uni), missing
egen teachfem_uni = rowtotal(teachfem_pre_uni teachfem_prim_uni), missing

egen teachers2 = rowtotal(teachers_prim2 teachers_pre2), missing
egen teachfem2 = rowtotal(teachfem_prim2 teachfem_pre2), missing

gen teachers_share_uni = teachers_uni/teachers2
gen teachfem_share_uni = teachfem_uni/teachfem2

drop teachers_pre_until13 teachfem_pre_until13 teachers_pre_uni teachfem_pre_uni teachers_pre2 teachfem_pre2 teachers_prim_until13 teachfem_prim_until13 teachers_prim_uni teachfem_prim_uni teachers_prim2 teachfem_prim2 teachers_uni teachfem_uni teachers2 teachfem2

****************************************
************** QUADRO5 *****************
****************************************

label variable idadeprof_mf_ini_1 "Number of pre-school teachers age: 18-19"
label variable idadeprof_mf_ini_2 "Number of pre-school teachers age: 20-24"
label variable idadeprof_mf_ini_3 "Number of pre-school teachers age: 25-29"
label variable idadeprof_mf_ini_4 "Number of pre-school teachers age: 30-34"
label variable idadeprof_mf_ini_5 "Number of pre-school teachers age: 35-39"
label variable idadeprof_mf_ini_6 "Number of pre-school teachers age: 40+"

label variable idadeprof_f_ini_1 "Number of pre-school female teachers age: 18-19"
label variable idadeprof_f_ini_2 "Number of pre-school female teachers age: 20-24"
label variable idadeprof_f_ini_3 "Number of pre-school female teachers age: 25-29"
label variable idadeprof_f_ini_4 "Number of pre-school female teachers age: 30-34"
label variable idadeprof_f_ini_5 "Number of pre-school female teachers age: 35-39"
label variable idadeprof_f_ini_6 "Number of pre-school female teachers age: 40+"

label variable idadeprof_mf_ep_1 "Number of primary school teachers age: 18-19"
label variable idadeprof_mf_ep_2 "Number of primary school teachers age: 20-24"
label variable idadeprof_mf_ep_3 "Number of primary school teachers age: 25-29"
label variable idadeprof_mf_ep_4 "Number of primary school teachers age: 30-34"
label variable idadeprof_mf_ep_5 "Number of primary school teachers age: 35-39"
label variable idadeprof_mf_ep_6 "Number of primary school teachers age: 40+"

label variable idadeprof_f_ep_1 "Number of primary school female teachers age: 18-19"
label variable idadeprof_f_ep_2 "Number of primary school female teachers age: 20-24"
label variable idadeprof_f_ep_3 "Number of primary school female teachers age: 25-29"
label variable idadeprof_f_ep_4 "Number of primary school female teachers age: 30-34"
label variable idadeprof_f_ep_5 "Number of primary school female teachers age: 35-39"
label variable idadeprof_f_ep_6 "Number of primary school female teachers age: 40+"


egen teachers_pre = rowtotal(idadeprof_mf_ini_1 idadeprof_mf_ini_2 idadeprof_mf_ini_3 idadeprof_mf_ini_4 idadeprof_mf_ini_5 idadeprof_mf_ini_6), missing
egen teachfem_pre = rowtotal(idadeprof_f_ini_1 idadeprof_f_ini_2 idadeprof_f_ini_3 idadeprof_f_ini_4 idadeprof_f_ini_5 idadeprof_f_ini_6), missing

egen teachers_prim = rowtotal(idadeprof_mf_ep_1 idadeprof_mf_ep_2 idadeprof_mf_ep_3 idadeprof_mf_ep_4 idadeprof_mf_ep_5 idadeprof_mf_ep_6), missing
egen teachfem_prim = rowtotal(idadeprof_f_ep_1 idadeprof_f_ep_2 idadeprof_f_ep_3 idadeprof_f_ep_4 idadeprof_f_ep_5 idadeprof_f_ep_6), missing

rename idadeprof_mf_ini_1 	teachers_age18_pre
rename idadeprof_mf_ini_2  	teachers_age20_pre
rename idadeprof_mf_ini_3  	teachers_age25_pre
rename idadeprof_mf_ini_4  	teachers_age30_pre
rename idadeprof_mf_ini_5  	teachers_age35_pre
rename idadeprof_mf_ini_6  	teachers_age40_pre

rename idadeprof_f_ini_1  	teachfem_age18_pre
rename idadeprof_f_ini_2   	teachfem_age20_pre
rename idadeprof_f_ini_3   	teachfem_age25_pre
rename idadeprof_f_ini_4   	teachfem_age30_pre
rename idadeprof_f_ini_5   	teachfem_age35_pre
rename idadeprof_f_ini_6   	teachfem_age40_pre

rename idadeprof_mf_ep_1   	teachers_age18_prim
rename idadeprof_mf_ep_2   	teachers_age20_prim
rename idadeprof_mf_ep_3   	teachers_age25_prim
rename idadeprof_mf_ep_4    teachers_age30_prim
rename idadeprof_mf_ep_5    teachers_age35_prim
rename idadeprof_mf_ep_6    teachers_age40_prim

rename idadeprof_f_ep_1 	teachfem_age18_prim
rename idadeprof_f_ep_2  	teachfem_age20_prim
rename idadeprof_f_ep_3  	teachfem_age25_prim
rename idadeprof_f_ep_4  	teachfem_age30_prim
rename idadeprof_f_ep_5  	teachfem_age35_prim
rename idadeprof_f_ep_6 	teachfem_age40_prim

lab var teachers_pre 	"Number of pre-school teachers"
lab var teachfem_pre 	"Number of pre-school female teachers"
lab var teachers_prim 	"Number of primary school teachers"
lab var teachfem_prim	"Number of primary school female teachers"

order teachers_pre teachfem_pre teachers_prim teachfem_prim, after(teachfem_age40_prim)

****************************************
************** QUADRO6 *****************
****************************************

label variable aux_mf_1 "Number of secretaries"
label variable aux_mf_2 "Number of guards"
label variable aux_mf_3 "Number of cleaning assistants"
label variable aux_mf_4 "Number of teachers without class"
label variable aux_mf_5 "Number of other employees"

label variable aux_f_1 "Number of female secretaries"
label variable aux_f_2 "Number of female guards"
label variable aux_f_3 "Number of female cleaning assistants"
label variable aux_f_4 "Number of female teachers without class"
label variable aux_f_5 "Number of female other employees"

rename aux_mf_1 secretaries
rename aux_mf_2 guards
rename aux_mf_3 cleaners
rename aux_mf_4 other_teachers
rename aux_mf_5 other_empl
rename aux_f_1  secretaries_fem
rename aux_f_2  guards_fem
rename aux_f_3  cleaners_fem
rename aux_f_4  other_teachers_fem
rename aux_f_5  other_empl_fem

****************************************
************** QUADRO7 *****************
****************************************

label variable salas_blocos_1 "Number of classrooms: definite structure, prefrabricated blocks"
label variable salas_blocos_2 "Number of classrooms: provisional structure, prefrabricated blocks"
label variable salas_blocos_3 "Number of classrooms: improvised structure, prefrabricated blocks"

label variable salas_cimento_1 "Number of classrooms: definite structure, cement or bricks"
label variable salas_cimento_2 "Number of classrooms: provisional structure, cement or bricks"
label variable salas_cimento_3 "Number of classrooms: improvised structure, cement or bricks"

label variable salas_outros_1 "Number of classrooms: definite structure, other materials"
label variable salas_outros_2 "Number of classrooms: provisional structure, other materials"
label variable salas_outros_3 "Number of classrooms: improvised structure, other materials"

rename salas_blocos_1 	classrooms_def_blocks
rename salas_blocos_2 	classrooms_prov_blocks
rename salas_blocos_3 	classrooms_impr_blocks

rename salas_cimento_1 	classrooms_def_cement
rename salas_cimento_2 	classrooms_prov_cement
rename salas_cimento_3 	classrooms_impr_cement

rename salas_outros_1 	classrooms_def_other
rename salas_outros_2 	classrooms_prov_other
rename salas_outros_3	classrooms_impr_other

egen classrooms_def = rowtotal(classrooms_def_blocks classrooms_def_cement classrooms_def_other), missing
egen classrooms_prov = rowtotal(classrooms_prov_blocks classrooms_prov_cement classrooms_prov_other), missing
egen classrooms_impr = rowtotal(classrooms_impr_blocks classrooms_impr_cement classrooms_impr_other), missing

egen classrooms = rowtotal(classrooms_def_blocks classrooms_prov_blocks classrooms_impr_blocks classrooms_def_cement classrooms_prov_cement classrooms_impr_cement classrooms_def_other classrooms_prov_other classrooms_impr_other), missing

lab var classrooms_def 		"Number of classrooms with definite structure"
lab var classrooms_prov 	"Number of classrooms with provisional structure"
lab var classrooms_impr		"Number of classrooms with improvised structure"
lab var classrooms 			"Number of classrooms in total"

order classrooms_def classrooms_prov classrooms_impr classrooms, after(classrooms_impr_other)

****************************************
************** QUADRO8 *****************
****************************************

label variable n_carteiras_1 "Number of individual student desks (1 body)"
label variable n_carteiras_2 "Number of individual student desks (1 table + 1 chair)"
label variable n_carteiras_3 "Number of double student desks (1 body)"
label variable n_carteiras_4 "Number of double student desks (1 table + 1 chair)"
label variable n_carteiras_5 "Number of double student desks (1 table + 2 chairs)"
label variable n_carteiras_6 "Number of student desks with more than 2 seats"

label variable n_assentos_lugares_1 "Number of seats ind. desk (1 body)"
label variable n_assentos_lugares_2 "Number of seats ind. desk (1 table + 1 chair)"
label variable n_assentos_lugares_3 "Number of seats double desk (1 body)"
label variable n_assentos_lugares_4 "Number of seats double desk (1 table + 1 chair)"
label variable n_assentos_lugares_5 "Number of seats double desk (1 table + 2 chair)"
label variable n_assentos_lugares_6 "Number of seats desks with more than 2 seats"

rename n_carteiras_1 			desks_ind1
rename n_carteiras_2 			desks_ind2
rename n_carteiras_3 			desks_double1
rename n_carteiras_4 			desks_double2
rename n_carteiras_5 			desks_double3
rename n_carteiras_6 			desks_more
rename n_assentos_lugares_1 	seats_ind1
rename n_assentos_lugares_2 	seats_ind2
rename n_assentos_lugares_3 	seats_double1
rename n_assentos_lugares_4 	seats_double2
rename n_assentos_lugares_5 	seats_double3
rename n_assentos_lugares_6		seats_more

egen desks_ind = rowtotal(desks_ind1 desks_ind2), missing
egen desks_double = rowtotal(desks_double1 desks_double2 desks_double3), missing

egen seats_ind = rowtotal(seats_ind1 seats_ind2), missing
egen seats_double = rowtotal(seats_double1 seats_double2 seats_double3), missing


egen desks = rowtotal(desks_ind1 desks_ind2 desks_double1 desks_double2 desks_double3 desks_more), missing
egen seats = rowtotal(seats_ind1 seats_ind2 seats_double1 seats_double2 seats_double3 seats_more), missing


label variable ar_livre "Number of classes outside"
label variable quadros  "Number of chalkboards"
label variable secretarias "Number of teacher desks"

rename ar_livre 	outside_classes
rename quadros 		chalkboards
rename secretarias	teacher_desks

order desks_ind desks_double seats_ind seats_double desks seats, after(seats_more)

lab var desks_ind 		"Number of individual student desks"
lab var desks_double  	"Number of double student desks"

lab var seats_ind		"Number of seats ind. desk"
lab var seats_double	"Number of seats double desk"

lab var desks  			"Number of student desks"
lab var seats 			"Number of seats"


****************************************
************** QUADRO9 *****************
****************************************


rename manu_prof_ini_0(#) manu_teacher_pre_(#)
rename manu_alu_ini_0(#) manu_student_pre_(#)
rename manu_prof_1_0(#) manu_teacher_g1_(#)
rename manu_alu_1_0(#) manu_student_g1_(#)
rename manu_prof_2_0(#) manu_teacher_g2_(#)
rename manu_alu_2_0(#) manu_student_g2_(#)
rename manu_prof_3_0(#) manu_teacher_g3_(#)
rename manu_alu_3_0(#) manu_student_g3_(#)
rename manu_prof_4_0(#) manu_teacher_g4_(#)
rename manu_alu_4_0(#) manu_student_g4_(#)
rename manu_prof_5_0(#) manu_teacher_g5_(#)
rename manu_alu_5_0(#) manu_student_g5_(#)
rename manu_prof_6_0(#) manu_teacher_g6_(#)
rename manu_alu_6_0(#) manu_student_g6_(#)

rename manu_prof_ini_1(#) manu_teacher_pre_1(#)
rename manu_alu_ini_1(#) manu_student_pre_1(#)
rename manu_prof_1_1(#) manu_teacher_g1_1(#)
rename manu_alu_1_1(#) manu_student_g1_1(#)
rename manu_prof_2_1(#) manu_teacher_g2_1(#)
rename manu_alu_2_1(#) manu_student_g2_1(#)
rename manu_prof_3_1(#) manu_teacher_g3_1(#)
rename manu_alu_3_1(#) manu_student_g3_1(#)
rename manu_prof_4_1(#) manu_teacher_g4_1(#)
rename manu_alu_4_1(#) manu_student_g4_1(#)
rename manu_prof_5_1(#) manu_teacher_g5_1(#)
rename manu_alu_5_1(#) manu_student_g5_1(#)
rename manu_prof_6_1(#) manu_teacher_g6_1(#)
rename manu_alu_6_1(#) manu_student_g6_1(#)



forval x=1/12{
lab var manu_teacher_pre_`x' "Number of teacher manuals pre-school type`x'"
lab var manu_student_pre_`x' "Number of student manuals pre-school type`x'"
lab var manu_teacher_g1_`x' "Number of teacher manuals grade 1 type`x'"
lab var manu_student_g1_`x' "Number of student manuals grade 1 type`x'"
lab var manu_teacher_g2_`x' "Number of teacher manuals grade 2 type`x'"
lab var manu_student_g2_`x' "Number of student manuals grade 2 type`x'"
lab var manu_teacher_g3_`x' "Number of teacher manuals grade 3 type`x'"
lab var manu_student_g3_`x' "Number of student manuals grade 3 type`x'"
lab var manu_teacher_g4_`x' "Number of teacher manuals grade 4 type`x'"
lab var manu_student_g4_`x' "Number of student manuals grade 4 type`x'"
lab var manu_teacher_g5_`x' "Number of teacher manuals grade 5 type`x'"
lab var manu_student_g5_`x' "Number of student manuals grade 5 type`x'"
lab var manu_teacher_g6_`x' "Number of teacher manuals grade 6 type`x'"
lab var manu_student_g6_`x' "Number of student manuals grade 6 type`x'"
}


foreach var in manu_teacher_pre_1 manu_teacher_pre_2 manu_teacher_pre_3 manu_teacher_pre_4 manu_teacher_pre_5 manu_teacher_pre_6 manu_teacher_pre_7 manu_teacher_pre_8 manu_teacher_pre_9 manu_teacher_pre_10 manu_teacher_pre_11 manu_teacher_pre_12 manu_student_pre_1 manu_student_pre_2 manu_student_pre_3 manu_student_pre_4 manu_student_pre_5 manu_student_pre_6 manu_student_pre_7 manu_student_pre_8 manu_student_pre_9 manu_student_pre_10 manu_student_pre_11 manu_student_pre_12 manu_teacher_g1_1 manu_teacher_g1_2 manu_teacher_g1_3 manu_teacher_g1_4 manu_teacher_g1_5 manu_teacher_g1_6 manu_teacher_g1_7 manu_teacher_g1_8 manu_teacher_g1_9 manu_teacher_g1_10 manu_teacher_g1_11 manu_teacher_g1_12 manu_student_g1_1 manu_student_g1_2 manu_student_g1_3 manu_student_g1_4 manu_student_g1_5 manu_student_g1_6 manu_student_g1_7 manu_student_g1_8 manu_student_g1_9 manu_student_g1_10 manu_student_g1_11 manu_student_g1_12 manu_teacher_g2_1 manu_teacher_g2_2 manu_teacher_g2_3 manu_teacher_g2_4 manu_teacher_g2_5 manu_teacher_g2_6 manu_teacher_g2_7 manu_teacher_g2_8 manu_teacher_g2_9 manu_teacher_g2_10 manu_teacher_g2_11 manu_teacher_g2_12 manu_student_g2_1 manu_student_g2_2 manu_student_g2_3 manu_student_g2_4 manu_student_g2_5 manu_student_g2_6 manu_student_g2_7 manu_student_g2_8 manu_student_g2_9 manu_student_g2_10 manu_student_g2_11 manu_student_g2_12 manu_teacher_g3_1 manu_teacher_g3_2 manu_teacher_g3_3 manu_teacher_g3_4 manu_teacher_g3_5 manu_teacher_g3_6 manu_teacher_g3_7 manu_teacher_g3_8 manu_teacher_g3_9 manu_teacher_g3_10 manu_teacher_g3_11 manu_teacher_g3_12 manu_student_g3_1 manu_student_g3_2 manu_student_g3_3 manu_student_g3_4 manu_student_g3_5 manu_student_g3_6 manu_student_g3_7 manu_student_g3_8 manu_student_g3_9 manu_student_g3_10 manu_student_g3_11 manu_student_g3_12 manu_teacher_g4_1 manu_teacher_g4_2 manu_teacher_g4_3 manu_teacher_g4_4 manu_teacher_g4_5 manu_teacher_g4_6 manu_teacher_g4_7 manu_teacher_g4_8 manu_teacher_g4_9 manu_teacher_g4_10 manu_teacher_g4_11 manu_teacher_g4_12 manu_student_g4_1 manu_student_g4_2 manu_student_g4_3 manu_student_g4_4 manu_student_g4_5 manu_student_g4_6 manu_student_g4_7 manu_student_g4_8 manu_student_g4_9 manu_student_g4_10 manu_student_g4_11 manu_student_g4_12 manu_teacher_g5_1 manu_teacher_g5_2 manu_teacher_g5_3 manu_teacher_g5_4 manu_teacher_g5_5 manu_teacher_g5_6 manu_teacher_g5_7 manu_teacher_g5_8 manu_teacher_g5_9 manu_teacher_g5_10 manu_teacher_g5_11 manu_teacher_g5_12 manu_student_g5_1 manu_student_g5_2 manu_student_g5_3 manu_student_g5_4 manu_student_g5_5 manu_student_g5_6 manu_student_g5_7 manu_student_g5_8 manu_student_g5_9 manu_student_g5_10 manu_student_g5_11 manu_student_g5_12 manu_teacher_g6_1 manu_teacher_g6_2 manu_teacher_g6_3 manu_teacher_g6_4 manu_teacher_g6_5 manu_teacher_g6_6 manu_teacher_g6_7 manu_teacher_g6_8 manu_teacher_g6_9 manu_teacher_g6_10 manu_teacher_g6_11 manu_teacher_g6_12 manu_student_g6_1 manu_student_g6_2 manu_student_g6_3 manu_student_g6_4 manu_student_g6_5 manu_student_g6_6 manu_student_g6_7 manu_student_g6_8 manu_student_g6_9 manu_student_g6_10 manu_student_g6_11 manu_student_g6_12{
replace `var' = . if `var'==999
}

/*
*** Note that:

type 1:		Pre-school card
type 2:		Portuguese language
type 3:		Mathematics
type 4:		Estudo de meio
type 5:		Natural science
type 6:		History
type 7:		Geography
type 8:		Moral e civic
type 9:		Manual and plastic
type 10:	Music
type 11:	Physical education
type 12:	Others

*/

****************************************
************** QUADRO10 ****************
****************************************

label variable campo_para_desporto "Number of sports fields"
label variable biblioteca "Number of libraries"
label variable sala_de_informatica "Number of computers rooms"
label variable laboratorio_de_informatica "Number of computer labs"
label variable casa_de_banho "Number of bathrooms"
label variable cantina_escolar "Number of school canteens"
label variable agua     "School has access to water"
label variable electricidade "School has access to electricity"

rename campo_para_desporto 			sportfields
rename biblioteca 					libraries
rename sala_de_informatica 			computerrooms
rename laboratorio_de_informatica 	computerlabs
rename casa_de_banho 				bathrooms
rename cantina_escolar 				canteens
rename agua 						water
rename electricidade				electricity

gen sportfield = 1 if sportfields>0
replace sportfield = 0 if sportfields==0
replace sportfield = . if sportfields==.

gen library = 1 if libraries>0
replace library = 0 if libraries==0
replace library = . if libraries==.

gen bathroom = 1 if bathrooms>0
replace bathroom = 0 if bathrooms==0
replace bathroom = . if bathrooms==.

gen canteen = 1 if canteens>0
replace canteen = 0 if canteens==0
replace canteen = . if canteens==.


label variable sportfield "School has a sport field"
label variable library "School has a library"
label variable bathroom "School has a bathroom"
label variable canteen "School has a canteen"

foreach var in sportfields libraries computerrooms computerlabs bathrooms canteens water electricity{
replace `var' = . if inlist(`var',9,99)
}

gen version = 17

order version

lab var version "Version of form used"

save "$Endline_dtRaw/_intermediate files/admin17_new.dta", replace

********************************************************************************

********************************************************************************

********************************************************************************
****************************** OLD VERSION FORM ********************************
********************************************************************************

********************************************************************************

********************************************************************************

use "$Endline_dtRaw/admin/escolas17_oldversion.dta", clear

gen version = 16

order version

lab var version "Version of form used"

label variable escola_id "School ID"
label variable regime_de_ensino "Type of school"
label variable nome_da_escola "School name"
label variable n_da_escola "School number"
label variable numero_de_turnos_na_escola "Number of parts of the day with classes"
label variable ultima_classe_ensinada_na_escola "Highest class taught"
label variable n_de_horas_por_turno "Duration class periods (in hours)"

label variable director "School director name"
label variable idade_director "Director age"
label variable n_de_telefone "Director phone number"
label variable nivel_academico_d "Director education"
label variable especialidade_d "Director speciality"
label variable nome_do_sub_director_pedagogico "Deputy director name"
label variable nivel_academico_sd "Deputy director education"
label variable especialidade_sd "Deputy director speciality"

label variable n_de_horas_como_director_d "Director hours dedicated to director duties"
label variable n_de_horas_como_director_sd "Deputy director hours dedicated to director duties"
label variable n_de_horas_como_docente_d "Director hours dedicated to teaching"
label variable n_de_horas_como_docente_sd "Deputy director hours dedicated to teaching"

label variable data_dia "Date of completing the form (DAY)"
label variable data_mes "Date of completing the form (MONTH)"
label variable data_ano "Date of completing the form (YEAR)"

rename escola_id 							school_id
rename regime_de_ensino  					school_type
rename nome_da_escola  						school_name
rename n_da_escola  						school_number
rename numero_de_turnos_na_escola  			number_periods
rename ultima_classe_ensinada_na_escola  	highest_grade
rename n_de_horas_por_turno		  			period_hours
rename director  				 			director_name
rename idade_director  						director_age
rename n_de_telefone  						director_tel
rename nivel_academico_d  					director_edu
rename especialidade_d  					director_spec
rename nome_do_sub_director_pedagogico  	deputy_name
rename nivel_academico_sd  					deputy_edu
rename especialidade_sd  					deputy_spec
rename n_de_horas_como_director_d  			director_hoursdir
rename n_de_horas_como_director_sd  		deputy_hoursdir
rename n_de_horas_como_docente_d  			director_hoursteach
rename n_de_horas_como_docente_sd  			deputy_hoursteach
rename data_dia  							date_day
rename data_mes  							date_month
rename data_ano								date_year

drop ano school_type school_number

replace highest_grade = . if highest_grade==99

replace period_hours = . if inlist(period_hours,0,9)
replace period_hours = 4.5 if period_hours==4.3

*** figure out why 3.3 and 4.3 are not being replaced

foreach var in director_name director_edu director_spec deputy_name deputy_edu deputy_spec{
replace `var' = "" if `var'=="999                           "
replace `var' = "" if `var'=="999                 "
}

replace director_age=. if director_age==99

replace director_tel = . if director_tel==999

foreach var in director_hoursdir deputy_hoursdir director_hoursteach deputy_hoursteach{
replace `var' = . if `var'==99
}

replace director_hoursdir = . if director_hoursdir==0 & director_hoursteach==0
replace director_hoursteach = . if director_hoursdir==. & director_hoursteach==0

replace deputy_hoursdir = . if deputy_hoursdir==0 & deputy_hoursteach==0
replace deputy_hoursteach = . if deputy_hoursdir==. & deputy_hoursteach==0

replace date_day = . if date_day==99
replace date_month = . if date_month==99
replace date_year = 2017


****************************************
************** QUADRO1 *****************
****************************************

forval x=5/14{
lab var tot_mf_`x'_1 "Number of students pre-school age `x'"
lab var tot_mf_`x'_2 "Number of students grade 1 age `x'"
lab var tot_mf_`x'_3 "Number of students grade 2 age `x'"
lab var tot_mf_`x'_4 "Number of students grade 3 age `x'"
lab var tot_mf_`x'_5 "Number of students grade 4 age `x'"
lab var tot_mf_`x'_6 "Number of students grade 5 age `x'"
lab var tot_mf_`x'_7 "Number of students grade 6 age `x'"

lab var tot_f_`x'_1 "Number of girls pre-school age `x'"
lab var tot_f_`x'_2 "Number of girls grade 1 age `x'"
lab var tot_f_`x'_3 "Number of girls grade 2 age `x'"
lab var tot_f_`x'_4 "Number of girls grade 3 age `x'"
lab var tot_f_`x'_5 "Number of girls grade 4 age `x'"
lab var tot_f_`x'_6 "Number of girls grade 5 age `x'"
lab var tot_f_`x'_7 "Number of girls grade 6 age `x'"
}

rename tot_mf_(#)_1 students_pre_age(#)
rename tot_mf_(#)_2 students_g1_age(#)
rename tot_mf_(#)_3 students_g2_age(#)
rename tot_mf_(#)_4 students_g3_age(#)
rename tot_mf_(#)_5 students_g4_age(#)
rename tot_mf_(#)_6 students_g5_age(#)
rename tot_mf_(#)_7 students_g6_age(#)

rename tot_mf_(##)_1 students_pre_age(##)
rename tot_mf_(##)_2 students_g1_age(##)
rename tot_mf_(##)_3 students_g2_age(##)
rename tot_mf_(##)_4 students_g3_age(##)
rename tot_mf_(##)_5 students_g4_age(##)
rename tot_mf_(##)_6 students_g5_age(##)
rename tot_mf_(##)_7 students_g6_age(##)

rename tot_f_(#)_1 girls_pre_age(#)
rename tot_f_(#)_2 girls_g1_age(#)
rename tot_f_(#)_3 girls_g2_age(#)
rename tot_f_(#)_4 girls_g3_age(#)
rename tot_f_(#)_5 girls_g4_age(#)
rename tot_f_(#)_6 girls_g5_age(#)
rename tot_f_(#)_7 girls_g6_age(#)

rename tot_f_(##)_1 girls_pre_age(##)
rename tot_f_(##)_2 girls_g1_age(##)
rename tot_f_(##)_3 girls_g2_age(##)
rename tot_f_(##)_4 girls_g3_age(##)
rename tot_f_(##)_5 girls_g4_age(##)
rename tot_f_(##)_6 girls_g5_age(##)
rename tot_f_(##)_7 girls_g6_age(##)

egen students_pre = rowtotal(students_pre_age5 students_pre_age6 students_pre_age7 students_pre_age8 students_pre_age9 students_pre_age10 students_pre_age11 students_pre_age12 students_pre_age13 students_pre_age14), missing
egen girls_pre = rowtotal(girls_pre_age5 girls_pre_age6 girls_pre_age7 girls_pre_age8 girls_pre_age9 girls_pre_age10 girls_pre_age11 girls_pre_age12 girls_pre_age13 girls_pre_age14), missing

forval x=1/6{
egen students_g`x' = rowtotal(students_g`x'_age5 students_g`x'_age6 students_g`x'_age7 students_g`x'_age8 students_g`x'_age9 students_g`x'_age10 students_g`x'_age11 students_g`x'_age12 students_g`x'_age13 students_g`x'_age14), missing
egen girls_g`x' = rowtotal(girls_g`x'_age5 girls_g`x'_age6 girls_g`x'_age7 girls_g`x'_age8 girls_g`x'_age9 girls_g`x'_age10 girls_g`x'_age11 girls_g`x'_age12 girls_g`x'_age13 girls_g`x'_age14), missing
}

egen students = rowtotal(students_pre students_g1 students_g2 students_g3 students_g4 students_g5 students_g6)
egen girls = rowtotal(girls_pre girls_g1 girls_g2 girls_g3 girls_g4 girls_g5 girls_g6)



lab var students_pre 	"Number of students in pre-school"
lab var girls_pre  		"Number of girls in pre-school"
lab var students_g1  	"Number of students in grade 1"
lab var girls_g1  		"Number of girls in grade 1"
lab var students_g2  	"Number of students in grade 2"
lab var girls_g2  		"Number of girls in grade 2"
lab var students_g3  	"Number of students in grade 3"
lab var girls_g3  		"Number of girls in grade 3"
lab var students_g4 	"Number of students in grade 4"
lab var girls_g4  		"Number of girls in grade 4"
lab var students_g5  	"Number of students in grade 5"
lab var girls_g5  		"Number of girls in grade 5"
lab var students_g6  	"Number of students in grade 6"
lab var girls_g6  		"Number of girls in grade 6"
lab var students  		"Number of students in total"
lab var girls 			"Number of girls in total"


order students_pre girls_pre students_g1 girls_g1 students_g2 girls_g2 students_g3 girls_g3 students_g4 girls_g4 students_g5 girls_g5 students_g6 girls_g6 students girls, after(girls_g6_age14)



****************************************
************** QUADRO3 *****************
****************************************

label variable n_de_turmas_1 "Number of pre-school classes"
label variable n_de_turmas_2 "Number of 1st grade classes"
label variable n_de_turmas_3 "Number of 2nd grade classes"
label variable n_de_turmas_4 "Number of 3rd grade classes"
label variable n_de_turmas_5 "Number of 4th grade classes"
label variable n_de_turmas_6 "Number of 5th grade classes"
label variable n_de_turmas_7 "Number of 6th grade classes"

label variable n_de_turnos_1 "Number periods the pre-school classes or divided over"
label variable n_de_turnos_2 "Number periods the 1st grade classes or divided over"
label variable n_de_turnos_3 "Number periods the 2nd grade classes or divided over"
label variable n_de_turnos_4 "Number periods the 3rd grade classes or divided over"
label variable n_de_turnos_5 "Number periods the 4th grade classes or divided over"
label variable n_de_turnos_6 "Number periods the 5th grade classes or divided over"
label variable n_de_turnos_7 "Number periods the 6th grade classes or divided over"

rename n_de_turmas_1 		classes_pre
rename n_de_turmas_2 		classes_g1
rename n_de_turmas_3  		classes_g2
rename n_de_turmas_4   		classes_g3
rename n_de_turmas_5   		classes_g4
rename n_de_turmas_6   		classes_g5
rename n_de_turmas_7   		classes_g6

rename n_de_turnos_1   		periods_pre
rename n_de_turnos_2    	periods_g1
rename n_de_turnos_3    	periods_g2
rename n_de_turnos_4    	periods_g3
rename n_de_turnos_5    	periods_g4
rename n_de_turnos_6    	periods_g5
rename n_de_turnos_7   		periods_g6

egen classes = rowtotal(classes_pre classes_g1 classes_g2 classes_g3 classes_g4 classes_g5 classes_g6), missing

lab var classes "Number of classes in total"

order classes ,after(classes_g6)


****************************************
************** QUADRO1B ****************
****************************************

rename tot_mf_a_1 repeaters_g1
rename tot_mf_a_2 repeaters_g2
rename tot_mf_a_3 repeaters_g3
rename tot_mf_a_4 repeaters_g4
rename tot_mf_a_5 repeaters_g5
rename tot_mf_a_6 repeaters_g6

rename tot_f_a_1 repeatgirl_g1
rename tot_f_a_2 repeatgirl_g2
rename tot_f_a_3 repeatgirl_g3
rename tot_f_a_4 repeatgirl_g4
rename tot_f_a_5 repeatgirl_g5
rename tot_f_a_6 repeatgirl_g6

egen repeaters = rowtotal(repeaters_g1 repeaters_g2 repeaters_g3 repeaters_g4 repeaters_g5 repeaters_g6), missing
egen repeatgirl = rowtotal(repeatgirl_g1 repeatgirl_g2 repeatgirl_g3 repeatgirl_g4 repeatgirl_g5 repeatgirl_g6), missing

lab var repeaters_g1  	"Number of repeaters in grade 1"
lab var repeatgirl_g1  	"Number of repeating girls in grade 1"
lab var repeaters_g2  	"Number of repeaters in grade 2"
lab var repeatgirl_g2  	"Number of repeating girls in grade 2"
lab var repeaters_g3  	"Number of repeaters in grade 3"
lab var repeatgirl_g3  	"Number of repeating girls in grade 3"
lab var repeaters_g4 	"Number of repeaters in grade 4"
lab var repeatgirl_g4  	"Number of repeating girls in grade 4"
lab var repeaters_g5  	"Number of repeaters in grade 5"
lab var repeatgirl_g5  	"Number of repeating girls in grade 5"
lab var repeaters_g6  	"Number of repeaters in grade 6"
lab var repeatgirl_g6  	"Number of repeating girls in grade 6"
lab var repeaters  		"Number of repeaters in total"
lab var repeatgirl 		"Number of repeating girls in total"

order repeaters repeatgirl, after(repeatgirl_g6)

****************************************
************** QUADRO4 *****************
****************************************


label variable nec_mf_vis_1 "Number of students with visual disability in pre-school"
label variable nec_mf_vis_2 "Number of students with visual disability in grade 1"
label variable nec_mf_vis_3 "Number of students with visual disability in grade 2"
label variable nec_mf_vis_4 "Number of students with visual disability in grade 3"
label variable nec_mf_vis_5 "Number of students with visual disability in grade 4"
label variable nec_mf_vis_6 "Number of students with visual disability in grade 5"
label variable nec_mf_vis_7 "Number of students with visual disability in grade 6"

label variable nec_f_vis_1 "Number of girls with visual disability in pre-school"
label variable nec_f_vis_2 "Number of girls with visual disability in grade 1"
label variable nec_f_vis_3 "Number of girls with visual disability in grade 2"
label variable nec_f_vis_4 "Number of girls with visual disability in grade 3"
label variable nec_f_vis_5 "Number of girls with visual disability in grade 4"
label variable nec_f_vis_6 "Number of girls with visual disability in grade 5"
label variable nec_f_vis_7 "Number of girls with visual disability in grade 6"

label variable nec_mf_aud_1 "Number of students with auditory disability in pre-school"
label variable nec_mf_aud_2 "Number of students with auditory disability in grade 1"
label variable nec_mf_aud_3 "Number of students with auditory disability in grade 2"
label variable nec_mf_aud_4 "Number of students with auditory disability in grade 3"
label variable nec_mf_aud_5 "Number of students with auditory disability in grade 4"
label variable nec_mf_aud_6 "Number of students with auditory disability in grade 5"
label variable nec_mf_aud_7 "Number of students with auditory disability in grade 6"

label variable nec_f_aud_1 "Number of girls with auditory disability in pre-school"
label variable nec_f_aud_2 "Number of girls with auditory disability in grade 1"
label variable nec_f_aud_3 "Number of girls with auditory disability in grade 2"
label variable nec_f_aud_4 "Number of girls with auditory disability in grade 3"
label variable nec_f_aud_5 "Number of girls with auditory disability in grade 4"
label variable nec_f_aud_6 "Number of girls with auditory disability in grade 5"
label variable nec_f_aud_7 "Number of girls with auditory disability in grade 6"

label variable nec_mf_mot_1 "Number of students with motor disability in pre-school"
label variable nec_mf_mot_2 "Number of students with motor disability in grade 1"
label variable nec_mf_mot_3 "Number of students with motor disability in grade 2"
label variable nec_mf_mot_4 "Number of students with motor disability in grade 3"
label variable nec_mf_mot_5 "Number of students with motor disability in grade 4"
label variable nec_mf_mot_6 "Number of students with motor disability in grade 5"
label variable nec_mf_mot_7 "Number of students with motor disability in grade 6"

label variable nec_f_mot_1 "Number of girls with motor disability in pre-school"
label variable nec_f_mot_2 "Number of girls with motor disability in grade 1"
label variable nec_f_mot_3 "Number of girls with motor disability in grade 2"
label variable nec_f_mot_4 "Number of girls with motor disability in grade 3"
label variable nec_f_mot_5 "Number of girls with motor disability in grade 4"
label variable nec_f_mot_6 "Number of girls with motor disability in grade 5"
label variable nec_f_mot_7 "Number of girls with motor disability in grade 6"

label variable nec_mf_out_1 "Number of students with other disability in pre-school"
label variable nec_mf_out_2 "Number of students with other disability in grade 1"
label variable nec_mf_out_3 "Number of students with other disability in grade 2"
label variable nec_mf_out_4 "Number of students with other disability in grade 3"
label variable nec_mf_out_5 "Number of students with other disability in grade 4"
label variable nec_mf_out_6 "Number of students with other disability in grade 5"
label variable nec_mf_out_7 "Number of students with other disability in grade 6"

label variable nec_f_out_1 "Number of girls with other disability in pre-school"
label variable nec_f_out_2 "Number of girls with other disability in grade 1"
label variable nec_f_out_3 "Number of girls with other disability in grade 2"
label variable nec_f_out_4 "Number of girls with other disability in grade 3"
label variable nec_f_out_5 "Number of girls with other disability in grade 4"
label variable nec_f_out_6 "Number of girls with other disability in grade 5"
label variable nec_f_out_7 "Number of girls with other disability in grade 6"

rename nec_mf_vis_1 	disabled_visual_pre
rename nec_mf_vis_2  	disabled_visual_g1
rename nec_mf_vis_3  	disabled_visual_g2
rename nec_mf_vis_4  	disabled_visual_g3
rename nec_mf_vis_5  	disabled_visual_g4
rename nec_mf_vis_6  	disabled_visual_g5
rename nec_mf_vis_7  	disabled_visual_g6

rename nec_f_vis_1  	disabgirl_visual_pre
rename nec_f_vis_2  	disabgirl_visual_g1
rename nec_f_vis_3  	disabgirl_visual_g2
rename nec_f_vis_4  	disabgirl_visual_g3
rename nec_f_vis_5  	disabgirl_visual_g4
rename nec_f_vis_6  	disabgirl_visual_g5
rename nec_f_vis_7  	disabgirl_visual_g6

rename nec_mf_aud_1  	disabled_audio_pre
rename nec_mf_aud_2  	disabled_audio_g1
rename nec_mf_aud_3  	disabled_audio_g2
rename nec_mf_aud_4  	disabled_audio_g3
rename nec_mf_aud_5  	disabled_audio_g4
rename nec_mf_aud_6  	disabled_audio_g5
rename nec_mf_aud_7  	disabled_audio_g6

rename nec_f_aud_1  	disabgirl_audio_pre
rename nec_f_aud_2  	disabgirl_audio_g1
rename nec_f_aud_3  	disabgirl_audio_g2
rename nec_f_aud_4  	disabgirl_audio_g3
rename nec_f_aud_5  	disabgirl_audio_g4
rename nec_f_aud_6  	disabgirl_audio_g5
rename nec_f_aud_7  	disabgirl_audio_g6

rename nec_mf_mot_1  	disabled_motor_pre
rename nec_mf_mot_2  	disabled_motor_g1
rename nec_mf_mot_3  	disabled_motor_g2
rename nec_mf_mot_4  	disabled_motor_g3
rename nec_mf_mot_5  	disabled_motor_g4
rename nec_mf_mot_6  	disabled_motor_g5
rename nec_mf_mot_7  	disabled_motor_g6

rename nec_f_mot_1  	disabgirl_motor_pre
rename nec_f_mot_2  	disabgirl_motor_g1
rename nec_f_mot_3  	disabgirl_motor_g2
rename nec_f_mot_4  	disabgirl_motor_g3
rename nec_f_mot_5  	disabgirl_motor_g4
rename nec_f_mot_6  	disabgirl_motor_g5
rename nec_f_mot_7  	disabgirl_motor_g6

rename nec_mf_out_1  	disabled_other_pre
rename nec_mf_out_2  	disabled_other_g1
rename nec_mf_out_3  	disabled_other_g2
rename nec_mf_out_4  	disabled_other_g3
rename nec_mf_out_5  	disabled_other_g4
rename nec_mf_out_6  	disabled_other_g5
rename nec_mf_out_7  	disabled_other_g6

rename nec_f_out_1  	disabgirl_other_pre
rename nec_f_out_2  	disabgirl_other_g1
rename nec_f_out_3  	disabgirl_other_g2
rename nec_f_out_4  	disabgirl_other_g3
rename nec_f_out_5  	disabgirl_other_g4
rename nec_f_out_6  	disabgirl_other_g5
rename nec_f_out_7 		disabgirl_other_g6

egen disabled_pre = rowtotal(disabled_visual_pre disabled_audio_pre disabled_motor_pre disabled_other_pre), missing
egen disabgirl_pre = rowtotal(disabgirl_visual_pre disabgirl_audio_pre disabgirl_motor_pre disabgirl_other_pre), missing


forval x=1/6{
egen disabled_g`x' = rowtotal(disabled_visual_g`x' disabled_audio_g`x' disabled_motor_g`x' disabled_other_g`x'), missing
egen disabgirl_g`x' = rowtotal(disabgirl_visual_g`x' disabgirl_audio_g`x' disabgirl_motor_g`x' disabgirl_other_g`x'), missing
}

egen disabled_visual = rowtotal(disabled_visual_pre disabled_visual_g1 disabled_visual_g2 disabled_visual_g3 disabled_visual_g4 disabled_visual_g5 disabled_visual_g6), missing
egen disabgirl_visual = rowtotal(disabgirl_visual_pre disabgirl_visual_g1 disabgirl_visual_g2 disabgirl_visual_g3 disabgirl_visual_g4 disabgirl_visual_g5 disabgirl_visual_g6), missing

egen disabled_audio = rowtotal(disabled_audio_pre disabled_audio_g1 disabled_audio_g2 disabled_audio_g3 disabled_audio_g4 disabled_audio_g5 disabled_audio_g6), missing
egen disabgirl_audio = rowtotal(disabgirl_audio_pre disabgirl_audio_g1 disabgirl_audio_g2 disabgirl_audio_g3 disabgirl_audio_g4 disabgirl_audio_g5 disabgirl_audio_g6), missing

egen disabled_motor = rowtotal(disabled_motor_pre disabled_motor_g1 disabled_motor_g2 disabled_motor_g3 disabled_motor_g4 disabled_motor_g5 disabled_motor_g6), missing
egen disabgirl_motor = rowtotal(disabgirl_motor_pre disabgirl_motor_g1 disabgirl_motor_g2 disabgirl_motor_g3 disabgirl_motor_g4 disabgirl_motor_g5 disabgirl_motor_g6), missing

egen disabled_other = rowtotal(disabled_other_pre disabled_other_g1 disabled_other_g2 disabled_other_g3 disabled_other_g4 disabled_other_g5 disabled_other_g6), missing
egen disabgirl_other = rowtotal(disabgirl_other_pre disabgirl_other_g1 disabgirl_other_g2 disabgirl_other_g3 disabgirl_other_g4 disabgirl_other_g5 disabgirl_other_g6), missing

egen disabled = rowtotal(disabled_visual disabled_audio disabled_motor disabled_other), missing
egen disabgirl = rowtotal(disabgirl_visual disabgirl_audio disabgirl_motor disabgirl_other), missing

order disabled_pre disabgirl_pre disabled_g1 disabgirl_g1 disabled_g2 disabgirl_g2 disabled_g3 disabgirl_g3 disabled_g4 disabgirl_g4 disabled_g5 disabgirl_g5 disabled_g6 disabgirl_g6 disabled_visual disabgirl_visual disabled_audio disabgirl_audio disabled_motor disabgirl_motor disabled_other disabgirl_other disabled disabgirl, after(disabgirl_other_g6)

lab var disabled_pre 		"Number of disabled students in pre-school"
lab var disabgirl_pre 	 	"Number of disabled girls in pre-school"
lab var disabled_g1  		"Number of disabled students in grade 1"
lab var disabgirl_g1  		"Number of disabled girls in grade 1"
lab var disabled_g2  		"Number of disabled students in grade 2"
lab var disabgirl_g2  		"Number of disabled girls in grade 2"
lab var disabled_g3  		"Number of disabled students in grade 3"
lab var disabgirl_g3  		"Number of disabled girls in grade 3"
lab var disabled_g4 		"Number of disabled students in grade 4"
lab var disabgirl_g4  		"Number of disabled girls in grade 4"
lab var disabled_g5  		"Number of disabled students in grade 5"
lab var disabgirl_g5  		"Number of disabled girls in grade 5"
lab var disabled_g6  		"Number of disabled students in grade 6"
lab var disabgirl_g6  		"Number of disabled girls in grade 6"
lab var disabled  			"Number of disabled students in total"
lab var disabgirl 			"Number of disabled girls in total"

lab var disabled_visual 	"Number of students with visual disability"
lab var disabgirl_visual  	"Number of girls with visual disability"
lab var disabled_audio  	"Number of students with auditory disability"
lab var disabgirl_audio  	"Number of girls with auditory disability"
lab var disabled_motor  	"Number of students with motor disability"
lab var disabgirl_motor  	"Number of girls with motor disability"
lab var disabled_other  	"Number of students with other disability"
lab var disabgirl_other 	"Number of girls with other disability"

****************************************
************** QUADRO5 *****************
****************************************

label variable nivprof_mf_6_ini_1 "Pre-school teachers education: until grade 6"
label variable nivprof_mf_6_ini_2 "Pre-school teachers education: until grade 6 without pedagogical training"
label variable nivprof_f_6_ini_1 "Pre-school female teachers education: until grade 6"
label variable nivprof_f_6_ini_2 "Pre-school female teachers education: until grade 6 without pedagogical training"

label variable nivprof_mf_9_ini_1 "Pre-school teachers education: grade 7-8"
label variable nivprof_mf_9_ini_2 "Pre-school teachers education: grade 7-8  without pedagogical training"
label variable nivprof_f_9_ini_1 "Pre-school female teachers education: grade 7-8 "
label variable nivprof_f_9_ini_2 "Pre-school female teachers education: grade 7-8  without pedagogical training"

label variable nivprof_mf_11_ini_1 "Pre-school teachers education: grade 9-10"
label variable nivprof_mf_11_ini_2 "Pre-school teachers education: grade 9-10  without pedagogical training"
label variable nivprof_f_11_ini_1 "Pre-school female teachers education: grade 9-10 "
label variable nivprof_f_11_ini_2 "Pre-school female teachers education: grade 9-10  without pedagogical training"

label variable nivprof_mf_13_ini_1 "Pre-school teachers education: grade 11-13"
label variable nivprof_mf_13_ini_2 "Pre-school teachers education: grade 11-13  without pedagogical training"
label variable nivprof_f_13_ini_1 "Pre-school female teachers education: grade 11-13 "
label variable nivprof_f_13_ini_2 "Pre-school female teachers education: grade 11-13  without pedagogical training"

label variable nivprof_mf_bach_ini_1 "Pre-school teachers education: bachelor"
label variable nivprof_mf_bach_ini_2 "Pre-school teachers education: bachelor  without pedagogical training"
label variable nivprof_f_bach_ini_1 "Pre-school female teachers education: bachelor "
label variable nivprof_f_bach_ini_2 "Pre-school female teachers education: bachelor  without pedagogical training"

label variable nivprof_mf_lic_ini_1 "Pre-school teachers education: graduated or more"
label variable nivprof_mf_lic_ini_2 "Pre-school teachers education: graduated or more  without pedagogical training"
label variable nivprof_f_lic_ini_1 "Pre-school female teachers education: graduated or more "
label variable nivprof_f_lic_ini_2 "Pre-school female teachers education: graduated or more  without pedagogical training"


label variable nivprof_mf_6_1 "Primary school teachers education: until grade 6"
label variable nivprof_mf_6_2 "Primary school teachers education: until grade 6 without pedagogical training"
label variable nivprof_f_6_1 "Primary school female teachers education: until grade 6"
label variable nivprof_f_6_2 "Primary school female teachers education: until grade 6 without pedagogical training"

label variable nivprof_mf_9_1 "Primary school teachers education: grade 7-8"
label variable nivprof_mf_9_2 "Primary school teachers education: grade 7-8 without pedagogical training"
label variable nivprof_f_9_1 "Primary school female teachers education: grade 7-8"
label variable nivprof_f_9_2 "Primary school female teachers education: grade 7-8 without pedagogical training"

label variable nivprof_mf_11_1 "Primary school teachers education: grade 9-10"
label variable nivprof_mf_11_2 "Primary school teachers education: grade 9-10 without pedagogical training"
label variable nivprof_f_11_1 "Primary school female teachers education: grade 9-10"
label variable nivprof_f_11_2 "Primary school female teachers education: grade 9-10 without pedagogical training"

label variable nivprof_mf_13_1 "Primary school teachers education: grade 11-13"
label variable nivprof_mf_13_2 "Primary school teachers education: grade 11-13 without pedagogical training"
label variable nivprof_f_13_1 "Primary school female teachers education: grade 11-13"
label variable nivprof_f_13_2 "Primary school female teachers education: grade 11-13 without pedagogical training"

label variable nivprof_mf_bach_1 "Primary school teachers education: bachelor"
label variable nivprof_mf_bach_2 "Primary school teachers education: bachelor without pedagogical training"
label variable nivprof_f_bach_1 "Primary school female teachers education: bachelor"
label variable nivprof_f_bach_2 "Primary school female teachers education: bachelor without pedagogical training"

label variable nivprof_mf_lic_1 "Primary school teachers education: graduated or more"
label variable nivprof_mf_lic_2 "Primary school teachers education: graduated or more  without pedagogical training"
label variable nivprof_f_lic_1 "Primary school female teachers education: graduated or more "
label variable nivprof_f_lic_2 "Primary school female teachers education: graduated or more  without pedagogical training"



foreach var in nivprof_mf_6_ini_1 nivprof_mf_6_ini_2 nivprof_f_6_ini_1 nivprof_f_6_ini_2 nivprof_mf_9_ini_1 nivprof_mf_9_ini_2 nivprof_f_9_ini_1 nivprof_f_9_ini_2 nivprof_mf_11_ini_1 nivprof_mf_11_ini_2 nivprof_f_11_ini_1 nivprof_f_11_ini_2 nivprof_mf_13_ini_1 nivprof_mf_13_ini_2 nivprof_f_13_ini_1 nivprof_f_13_ini_2 nivprof_mf_bach_ini_1 nivprof_mf_bach_ini_2 nivprof_f_bach_ini_1 nivprof_f_bach_ini_2 nivprof_mf_lic_ini_1 nivprof_mf_lic_ini_2 nivprof_f_lic_ini_1 nivprof_f_lic_ini_2 nivprof_mf_6_1 nivprof_mf_6_2 nivprof_f_6_1 nivprof_f_6_2 nivprof_mf_9_1 nivprof_mf_9_2 nivprof_f_9_1 nivprof_f_9_2 nivprof_mf_11_1 nivprof_mf_11_2 nivprof_f_11_1 nivprof_f_11_2 nivprof_mf_13_1 nivprof_mf_13_2 nivprof_f_13_1 nivprof_f_13_2 nivprof_mf_bach_1 nivprof_mf_bach_2 nivprof_f_bach_1 nivprof_f_bach_2 nivprof_mf_lic_1 nivprof_mf_lic_2 nivprof_f_lic_1 nivprof_f_lic_2{
replace `var' = . if `var'==99
}

rename nivprof_mf_9_ini_1 	nivprof_mf_7x_ini_1
rename nivprof_mf_9_ini_2  	nivprof_mf_7x_ini_2
rename nivprof_f_9_ini_1  	nivprof_f_7x_ini_1
rename nivprof_f_9_ini_2  	nivprof_f_7x_ini_2
rename nivprof_mf_11_ini_1  nivprof_mf_9_ini_1
rename nivprof_mf_11_ini_2  nivprof_mf_9_ini_2
rename nivprof_f_11_ini_1  	nivprof_f_9_ini_1
rename nivprof_f_11_ini_2  	nivprof_f_9_ini_2
rename nivprof_mf_13_ini_1  nivprof_mf_11_ini_1
rename nivprof_mf_13_ini_2  nivprof_mf_11_ini_2
rename nivprof_f_13_ini_1  	nivprof_f_11_ini_1
rename nivprof_f_13_ini_2  	nivprof_f_11_ini_2
rename nivprof_mf_9_1  		nivprof_mf_7x_1
rename nivprof_mf_9_2  		nivprof_mf_7x_2
rename nivprof_f_9_1  		nivprof_f_7x_1
rename nivprof_f_9_2  		nivprof_f_7x_2
rename nivprof_mf_11_1  	nivprof_mf_9_1
rename nivprof_mf_11_2  	nivprof_mf_9_2
rename nivprof_f_11_1  		nivprof_f_9_1
rename nivprof_f_11_2  		nivprof_f_9_2
rename nivprof_mf_13_1  	nivprof_mf_11_1
rename nivprof_mf_13_2  	nivprof_mf_11_2
rename nivprof_f_13_1  		nivprof_f_11_1
rename nivprof_f_13_2		nivprof_f_11_2

rename nivprof*_1 nivprof*


egen teachers_pre_until13 = rowtotal(nivprof_mf_6_ini nivprof_mf_6_ini_2 nivprof_mf_7x_ini nivprof_mf_7x_ini_2 nivprof_mf_9_ini nivprof_mf_9_ini_2 nivprof_mf_11_ini nivprof_mf_11_ini_2), missing
egen teachfem_pre_until13 = rowtotal(nivprof_f_6_ini nivprof_f_6_ini_2 nivprof_f_7x_ini nivprof_f_7x_ini_2 nivprof_f_9_ini nivprof_f_9_ini_2 nivprof_f_11_ini nivprof_f_11_ini_2), missing

egen teachers_pre_uni = rowtotal(nivprof_mf_bach_ini nivprof_mf_bach_ini_2 nivprof_mf_lic_ini nivprof_mf_lic_ini_2), missing
egen teachfem_pre_uni = rowtotal(nivprof_f_bach_ini nivprof_f_bach_ini_2 nivprof_f_lic_ini nivprof_f_lic_ini_2), missing

egen teachers_pre2 = rowtotal(teachers_pre_until13 teachers_pre_uni), missing
egen teachfem_pre2 = rowtotal(teachfem_pre_until13 teachfem_pre_uni), missing

egen teachers_prim_until13 = rowtotal(nivprof_mf_6 nivprof_mf_6_2 nivprof_mf_7x nivprof_mf_7x_2 nivprof_mf_9 nivprof_mf_9_2 nivprof_mf_11 nivprof_mf_11_2), missing
egen teachfem_prim_until13 = rowtotal(nivprof_f_6 nivprof_f_6_2 nivprof_f_7x nivprof_f_7x_2 nivprof_f_9 nivprof_f_9_2 nivprof_f_11 nivprof_f_11_2), missing

egen teachers_prim_uni = rowtotal(nivprof_mf_bach nivprof_mf_bach_2 nivprof_mf_lic nivprof_mf_lic_2), missing
egen teachfem_prim_uni = rowtotal(nivprof_f_bach nivprof_f_bach_2 nivprof_f_lic nivprof_f_lic_2), missing

egen teachers_prim2 = rowtotal(teachers_prim_until13 teachers_prim_uni), missing
egen teachfem_prim2 = rowtotal(teachfem_prim_until13 teachfem_prim_uni), missing

egen teachers_uni = rowtotal(teachers_pre_uni teachers_prim_uni), missing
egen teachfem_uni = rowtotal(teachfem_pre_uni teachfem_prim_uni), missing

egen teachers2 = rowtotal(teachers_prim2 teachers_pre2), missing
egen teachfem2 = rowtotal(teachfem_prim2 teachfem_pre2), missing

gen teachers_share_uni = teachers_uni/teachers2
gen teachfem_share_uni = teachfem_uni/teachfem2

drop teachers_pre_until13 teachfem_pre_until13 teachers_pre_uni teachfem_pre_uni teachers_pre2 teachfem_pre2 teachers_prim_until13 teachfem_prim_until13 teachers_prim_uni teachfem_prim_uni teachers_prim2 teachfem_prim2 teachers_uni teachfem_uni teachers2 teachfem2


****************************************
************** QUADRO6 *****************
****************************************


label variable idadeprof_mf_ini_1 "Number of pre-school teachers age: 18-19"
label variable idadeprof_mf_ini_2 "Number of pre-school teachers age: 20-24"
label variable idadeprof_mf_ini_3 "Number of pre-school teachers age: 25-29"
label variable idadeprof_mf_ini_4 "Number of pre-school teachers age: 30-34"
label variable idadeprof_mf_ini_5 "Number of pre-school teachers age: 35-39"
label variable idadeprof_mf_ini_6 "Number of pre-school teachers age: 40+"

label variable idadeprof_f_ini_1 "Number of pre-school female teachers age: 18-19"
label variable idadeprof_f_ini_2 "Number of pre-school female teachers age: 20-24"
label variable idadeprof_f_ini_3 "Number of pre-school female teachers age: 25-29"
label variable idadeprof_f_ini_4 "Number of pre-school female teachers age: 30-34"
label variable idadeprof_f_ini_5 "Number of pre-school female teachers age: 35-39"
label variable idadeprof_f_ini_6 "Number of pre-school female teachers age: 40+"

label variable idadeprof_mf_ep_1 "Number of primary school teachers age: 18-19"
label variable idadeprof_mf_ep_2 "Number of primary school teachers age: 20-24"
label variable idadeprof_mf_ep_3 "Number of primary school teachers age: 25-29"
label variable idadeprof_mf_ep_4 "Number of primary school teachers age: 30-34"
label variable idadeprof_mf_ep_5 "Number of primary school teachers age: 35-39"
label variable idadeprof_mf_ep_6 "Number of primary school teachers age: 40+"

label variable idadeprof_f_ep_1 "Number of primary school female teachers age: 18-19"
label variable idadeprof_f_ep_2 "Number of primary school female teachers age: 20-24"
label variable idadeprof_f_ep_3 "Number of primary school female teachers age: 25-29"
label variable idadeprof_f_ep_4 "Number of primary school female teachers age: 30-34"
label variable idadeprof_f_ep_5 "Number of primary school female teachers age: 35-39"
label variable idadeprof_f_ep_6 "Number of primary school female teachers age: 40+"


egen teachers_pre = rowtotal(idadeprof_mf_ini_1 idadeprof_mf_ini_2 idadeprof_mf_ini_3 idadeprof_mf_ini_4 idadeprof_mf_ini_5 idadeprof_mf_ini_6), missing
egen teachfem_pre = rowtotal(idadeprof_f_ini_1 idadeprof_f_ini_2 idadeprof_f_ini_3 idadeprof_f_ini_4 idadeprof_f_ini_5 idadeprof_f_ini_6), missing

egen teachers_prim = rowtotal(idadeprof_mf_ep_1 idadeprof_mf_ep_2 idadeprof_mf_ep_3 idadeprof_mf_ep_4 idadeprof_mf_ep_5 idadeprof_mf_ep_6), missing
egen teachfem_prim = rowtotal(idadeprof_f_ep_1 idadeprof_f_ep_2 idadeprof_f_ep_3 idadeprof_f_ep_4 idadeprof_f_ep_5 idadeprof_f_ep_6), missing

rename idadeprof_mf_ini_1 	teachers_age18_pre
rename idadeprof_mf_ini_2  	teachers_age20_pre
rename idadeprof_mf_ini_3  	teachers_age25_pre
rename idadeprof_mf_ini_4  	teachers_age30_pre
rename idadeprof_mf_ini_5  	teachers_age35_pre
rename idadeprof_mf_ini_6  	teachers_age40_pre

rename idadeprof_f_ini_1  	teachfem_age18_pre
rename idadeprof_f_ini_2   	teachfem_age20_pre
rename idadeprof_f_ini_3   	teachfem_age25_pre
rename idadeprof_f_ini_4   	teachfem_age30_pre
rename idadeprof_f_ini_5   	teachfem_age35_pre
rename idadeprof_f_ini_6   	teachfem_age40_pre

rename idadeprof_mf_ep_1   	teachers_age18_prim
rename idadeprof_mf_ep_2   	teachers_age20_prim
rename idadeprof_mf_ep_3   	teachers_age25_prim
rename idadeprof_mf_ep_4    teachers_age30_prim
rename idadeprof_mf_ep_5    teachers_age35_prim
rename idadeprof_mf_ep_6    teachers_age40_prim

rename idadeprof_f_ep_1 	teachfem_age18_prim
rename idadeprof_f_ep_2  	teachfem_age20_prim
rename idadeprof_f_ep_3  	teachfem_age25_prim
rename idadeprof_f_ep_4  	teachfem_age30_prim
rename idadeprof_f_ep_5  	teachfem_age35_prim
rename idadeprof_f_ep_6 	teachfem_age40_prim

lab var teachers_pre 	"Number of pre-school teachers"
lab var teachfem_pre 	"Number of pre-school female teachers"
lab var teachers_prim 	"Number of primary school teachers"
lab var teachfem_prim	"Number of primary school female teachers"

order teachers_pre teachfem_pre teachers_prim teachfem_prim, after(teachfem_age40_prim)



****************************************
************** QUADRO7 *****************
****************************************

label variable aux_mf_1 "Number of secretaries"
label variable aux_mf_2 "Number of guards"
label variable aux_mf_3 "Number of cleaning assistants"
label variable aux_mf_4 "Number of teachers without class"
label variable aux_mf_5 "Number of other employees"

label variable aux_f_1 "Number of female secretaries"
label variable aux_f_2 "Number of female guards"
label variable aux_f_3 "Number of female cleaning assistants"
label variable aux_f_4 "Number of female teachers without class"
label variable aux_f_5 "Number of female other employees"

rename aux_mf_1 secretaries
rename aux_mf_2 guards
rename aux_mf_3 cleaners
rename aux_mf_4 other_teachers
rename aux_mf_5 other_empl
rename aux_f_1  secretaries_fem
rename aux_f_2  guards_fem
rename aux_f_3  cleaners_fem
rename aux_f_4  other_teachers_fem
rename aux_f_5  other_empl_fem

****************************************
************** QUADRO8A ****************
****************************************

label variable salas_blocos_1 "Number of classrooms: definite structure, prefrabricated blocks"
label variable salas_blocos_2 "Number of classrooms: provisional structure, prefrabricated blocks"
label variable salas_blocos_3 "Number of classrooms: improvised structure, prefrabricated blocks"

label variable salas_cimento_1 "Number of classrooms: definite structure, cement or bricks"
label variable salas_cimento_2 "Number of classrooms: provisional structure, cement or bricks"
label variable salas_cimento_3 "Number of classrooms: improvised structure, cement or bricks"

label variable salas_outros_1 "Number of classrooms: definite structure, other materials"
label variable salas_outros_2 "Number of classrooms: provisional structure, other materials"
label variable salas_outros_3 "Number of classrooms: improvised structure, other materials"

rename salas_blocos_1 	classrooms_def_blocks
rename salas_blocos_2 	classrooms_prov_blocks
rename salas_blocos_3 	classrooms_impr_blocks

rename salas_cimento_1 	classrooms_def_cement
rename salas_cimento_2 	classrooms_prov_cement
rename salas_cimento_3 	classrooms_impr_cement

rename salas_outros_1 	classrooms_def_other
rename salas_outros_2 	classrooms_prov_other
rename salas_outros_3	classrooms_impr_other

egen classrooms_def = rowtotal(classrooms_def_blocks classrooms_def_cement classrooms_def_other), missing
egen classrooms_prov = rowtotal(classrooms_prov_blocks classrooms_prov_cement classrooms_prov_other), missing
egen classrooms_impr = rowtotal(classrooms_impr_blocks classrooms_impr_cement classrooms_impr_other), missing

egen classrooms = rowtotal(classrooms_def_blocks classrooms_prov_blocks classrooms_impr_blocks classrooms_def_cement classrooms_prov_cement classrooms_impr_cement classrooms_def_other classrooms_prov_other classrooms_impr_other), missing

lab var classrooms_def 		"Number of classrooms with definite structure"
lab var classrooms_prov 	"Number of classrooms with provisional structure"
lab var classrooms_impr		"Number of classrooms with improvised structure"
lab var classrooms 			"Number of classrooms in total"

order classrooms_def classrooms_prov classrooms_impr classrooms, after(classrooms_impr_other)

****************************************
************** QUADRO8B ****************
****************************************

label variable n_carteiras_1 "Number of individual student desks"
label variable n_carteiras_2 "Number of double student desks"
label variable n_carteiras_3 "Number of student desks with more than 2 seats"


label variable n_assentos_lugares_1 "Number of seats ind. desk"
label variable n_assentos_lugares_2 "Number of seats double desk"
label variable n_assentos_lugares_3 "Number of seats desks with more than 2 seats"


rename n_carteiras_1 			desks_ind
rename n_carteiras_2 			desks_double
rename n_carteiras_3 			desks_more

rename n_assentos_lugares_1 	seats_ind
rename n_assentos_lugares_2 	seats_double
rename n_assentos_lugares_3 	seats_more

egen desks = rowtotal(desks_ind desks_double desks_more), missing
egen seats = rowtotal(seats_ind seats_double seats_more), missing

order desks seats, after(seats_more)

lab var desks  			"Number of student desks"
lab var seats 			"Number of seats"



label variable ar_livre "Number of classes outside"
label variable quadros  "Number of chalkboards"
label variable secretarias "Number of teacher desks"

rename ar_livre 	outside_classes
rename quadros 		chalkboards
rename secretarias	teacher_desks

foreach var in outside_classes chalkboards teacher_desks{
replace `var' = . if `var'==99
}


***************************************
************** QUADRO9 *****************
****************************************


rename manu_prof_ini_1 		manu_teacher_pre_1
rename manu_prof_ini_2  	manu_teacher_pre_2
rename manu_prof_ini_3  	manu_teacher_pre_3
rename manu_prof_ini_4  	manu_teacher_pre_5
rename manu_prof_ini_5  	manu_teacher_pre_12
rename manu_alu_ini_1  		manu_student_pre_1
rename manu_alu_ini_2  		manu_student_pre_2
rename manu_alu_ini_3  		manu_student_pre_3
rename manu_alu_ini_4  		manu_student_pre_5
rename manu_alu_ini_5  		manu_student_pre_12

rename manu_prof_1_1  		manu_teacher_g1_1
rename manu_prof_1_2  		manu_teacher_g1_2
rename manu_prof_1_3  		manu_teacher_g1_3
rename manu_prof_1_4  		manu_teacher_g1_5
rename manu_prof_1_5  		manu_teacher_g1_12
rename manu_alu_1_1  		manu_student_g1_1
rename manu_alu_1_2  		manu_student_g1_2
rename manu_alu_1_3  		manu_student_g1_3
rename manu_alu_1_4  		manu_student_g1_5
rename manu_alu_1_5  		manu_student_g1_12

rename manu_prof_2_1  		manu_teacher_g2_1
rename manu_prof_2_2  		manu_teacher_g2_2
rename manu_prof_2_3  		manu_teacher_g2_3
rename manu_prof_2_4  		manu_teacher_g2_5
rename manu_prof_2_5  		manu_teacher_g2_12
rename manu_alu_2_1  		manu_student_g2_1
rename manu_alu_2_2  		manu_student_g2_2
rename manu_alu_2_3  		manu_student_g2_3
rename manu_alu_2_4  		manu_student_g2_5
rename manu_alu_2_5  		manu_student_g2_12

rename manu_prof_3_1  		manu_teacher_g3_1
rename manu_prof_3_2  		manu_teacher_g3_2
rename manu_prof_3_3  		manu_teacher_g3_3
rename manu_prof_3_4  		manu_teacher_g3_5
rename manu_prof_3_5  		manu_teacher_g3_12
rename manu_alu_3_1  		manu_student_g3_1
rename manu_alu_3_2  		manu_student_g3_2
rename manu_alu_3_3  		manu_student_g3_3
rename manu_alu_3_4  		manu_student_g3_5
rename manu_alu_3_5  		manu_student_g3_12

rename manu_prof_4_1  		manu_teacher_g4_1
rename manu_prof_4_2  		manu_teacher_g4_2
rename manu_prof_4_3  		manu_teacher_g4_3
rename manu_prof_4_4  		manu_teacher_g4_5
rename manu_prof_4_5  		manu_teacher_g4_12
rename manu_alu_4_1  		manu_student_g4_1
rename manu_alu_4_2  		manu_student_g4_2
rename manu_alu_4_3  		manu_student_g4_3
rename manu_alu_4_4  		manu_student_g4_5
rename manu_alu_4_5  		manu_student_g4_12

rename manu_prof_5_1  		manu_teacher_g5_1
rename manu_prof_5_2  		manu_teacher_g5_2
rename manu_prof_5_3  		manu_teacher_g5_3
rename manu_prof_5_4  		manu_teacher_g5_5
rename manu_prof_5_5  		manu_teacher_g5_12
rename manu_alu_5_1  		manu_student_g5_1
rename manu_alu_5_2  		manu_student_g5_2
rename manu_alu_5_3  		manu_student_g5_3
rename manu_alu_5_4  		manu_student_g5_5
rename manu_alu_5_5  		manu_student_g5_12

rename manu_prof_6_1  		manu_teacher_g6_1
rename manu_prof_6_2  		manu_teacher_g6_2
rename manu_prof_6_3  		manu_teacher_g6_3
rename manu_prof_6_4  		manu_teacher_g6_5
rename manu_prof_6_5  		manu_teacher_g6_12
rename manu_alu_6_1  		manu_student_g6_1
rename manu_alu_6_2  		manu_student_g6_2
rename manu_alu_6_3  		manu_student_g6_3
rename manu_alu_6_4  		manu_student_g6_5
rename manu_alu_6_5			manu_student_g6_12


forval x=1/3{
lab var manu_teacher_pre_`x' "Number of teacher manuals pre-school type`x'"
lab var manu_student_pre_`x' "Number of student manuals pre-school type`x'"
lab var manu_teacher_g1_`x' "Number of teacher manuals grade 1 type`x'"
lab var manu_student_g1_`x' "Number of student manuals grade 1 type`x'"
lab var manu_teacher_g2_`x' "Number of teacher manuals grade 2 type`x'"
lab var manu_student_g2_`x' "Number of student manuals grade 2 type`x'"
lab var manu_teacher_g3_`x' "Number of teacher manuals grade 3 type`x'"
lab var manu_student_g3_`x' "Number of student manuals grade 3 type`x'"
lab var manu_teacher_g4_`x' "Number of teacher manuals grade 4 type`x'"
lab var manu_student_g4_`x' "Number of student manuals grade 4 type`x'"
lab var manu_teacher_g5_`x' "Number of teacher manuals grade 5 type`x'"
lab var manu_student_g5_`x' "Number of student manuals grade 5 type`x'"
lab var manu_teacher_g6_`x' "Number of teacher manuals grade 6 type`x'"
lab var manu_student_g6_`x' "Number of student manuals grade 6 type`x'"
}

lab var manu_teacher_pre_5 "Number of teacher manuals pre-school type5"
lab var manu_student_pre_5 "Number of student manuals pre-school type5"
lab var manu_teacher_g1_5 "Number of teacher manuals grade 1 type5"
lab var manu_student_g1_5 "Number of student manuals grade 1 type5"
lab var manu_teacher_g2_5 "Number of teacher manuals grade 2 type5"
lab var manu_student_g2_5 "Number of student manuals grade 2 type5"
lab var manu_teacher_g3_5 "Number of teacher manuals grade 3 type5"
lab var manu_student_g3_5 "Number of student manuals grade 3 type5"
lab var manu_teacher_g4_5 "Number of teacher manuals grade 4 type5"
lab var manu_student_g4_5 "Number of student manuals grade 4 type5"
lab var manu_teacher_g5_5 "Number of teacher manuals grade 5 type5"
lab var manu_student_g5_5 "Number of student manuals grade 5 type5"
lab var manu_teacher_g6_5 "Number of teacher manuals grade 6 type5"
lab var manu_student_g6_5 "Number of student manuals grade 6 type5"

lab var manu_teacher_pre_12 "Number of teacher manuals pre-school type12"
lab var manu_student_pre_12 "Number of student manuals pre-school type12"
lab var manu_teacher_g1_12 "Number of teacher manuals grade 1 type12"
lab var manu_student_g1_12 "Number of student manuals grade 1 type12"
lab var manu_teacher_g2_12 "Number of teacher manuals grade 2 type12"
lab var manu_student_g2_12 "Number of student manuals grade 2 type12"
lab var manu_teacher_g3_12 "Number of teacher manuals grade 3 type12"
lab var manu_student_g3_12 "Number of student manuals grade 3 type12"
lab var manu_teacher_g4_12 "Number of teacher manuals grade 4 type12"
lab var manu_student_g4_12 "Number of student manuals grade 4 type12"
lab var manu_teacher_g5_12 "Number of teacher manuals grade 5 type12"
lab var manu_student_g5_12 "Number of student manuals grade 5 type12"
lab var manu_teacher_g6_12 "Number of teacher manuals grade 6 type12"
lab var manu_student_g6_12 "Number of student manuals grade 6 type12"


/*
*** Note that:

type 1:		Pre-school card
type 2:		Portuguese language
type 3:		Mathematics

type 5:		Natural science

type 12:	Others

*/

****************************************
************** QUADRO10 ****************
****************************************

label variable campo_para_desporto "School has a sport field"
label variable biblioteca "School has a library"
label variable casa_de_banho "School has a bathroom"
label variable cantina_escolar "School has a canteen"
label variable agua     "School has access to water"
label variable electricidade "School has access to electricity"

rename campo_para_desporto 			sportfield
rename biblioteca 					library
rename casa_de_banho 				bathroom
rename cantina_escolar 				canteen
rename agua 						water
rename electricidade				electricity

order canteen, after(bathroom)


foreach var in sportfield library bathroom water electricity canteen{
replace `var' = . if `var'==9
}


append using "$Endline_dtRaw/_intermediate files/admin17_new.dta"

drop repeaters_pre repeatgirl_pre

order morning_hours afternoon_hours night_hours, after(period_hours)
order repeaters_pre_age5 repeaters_g1_age5 repeaters_g2_age5 repeaters_g3_age5 repeaters_g4_age5 repeaters_g5_age5 repeaters_g6_age5 repeatgirl_pre_age5 repeatgirl_g1_age5 repeatgirl_g2_age5 repeatgirl_g3_age5 repeatgirl_g4_age5 repeatgirl_g5_age5 repeatgirl_g6_age5 repeaters_pre_age6 repeaters_g1_age6 repeaters_g2_age6 repeaters_g3_age6 repeaters_g4_age6 repeaters_g5_age6 repeaters_g6_age6 repeatgirl_pre_age6 repeatgirl_g1_age6 repeatgirl_g2_age6 repeatgirl_g3_age6 repeatgirl_g4_age6 repeatgirl_g5_age6 repeatgirl_g6_age6 repeaters_pre_age7 repeaters_g1_age7 repeaters_g2_age7 repeaters_g3_age7 repeaters_g4_age7 repeaters_g5_age7 repeaters_g6_age7 repeatgirl_pre_age7 repeatgirl_g1_age7 repeatgirl_g2_age7 repeatgirl_g3_age7 repeatgirl_g4_age7 repeatgirl_g5_age7 repeatgirl_g6_age7 repeaters_pre_age8 repeaters_g1_age8 repeaters_g2_age8 repeaters_g3_age8 repeaters_g4_age8 repeaters_g5_age8 repeaters_g6_age8 repeatgirl_pre_age8 repeatgirl_g1_age8 repeatgirl_g2_age8 repeatgirl_g3_age8 repeatgirl_g4_age8 repeatgirl_g5_age8 repeatgirl_g6_age8 repeaters_pre_age9 repeaters_g1_age9 repeaters_g2_age9 repeaters_g3_age9 repeaters_g4_age9 repeaters_g5_age9 repeaters_g6_age9 repeatgirl_pre_age9 repeatgirl_g1_age9 repeatgirl_g2_age9 repeatgirl_g3_age9 repeatgirl_g4_age9 repeatgirl_g5_age9 repeatgirl_g6_age9 repeaters_pre_age10 repeaters_g1_age10 repeaters_g2_age10 repeaters_g3_age10 repeaters_g4_age10 repeaters_g5_age10 repeaters_g6_age10 repeatgirl_pre_age10 repeatgirl_g1_age10 repeatgirl_g2_age10 repeatgirl_g3_age10 repeatgirl_g4_age10 repeatgirl_g5_age10 repeatgirl_g6_age10 repeaters_pre_age11 repeaters_g1_age11 repeaters_g2_age11 repeaters_g3_age11 repeaters_g4_age11 repeaters_g5_age11 repeaters_g6_age11 repeatgirl_pre_age11 repeatgirl_g1_age11 repeatgirl_g2_age11 repeatgirl_g3_age11 repeatgirl_g4_age11 repeatgirl_g5_age11 repeatgirl_g6_age11 repeaters_pre_age12 repeaters_g1_age12 repeaters_g2_age12 repeaters_g3_age12 repeaters_g4_age12 repeaters_g5_age12 repeaters_g6_age12 repeatgirl_pre_age12 repeatgirl_g1_age12 repeatgirl_g2_age12 repeatgirl_g3_age12 repeatgirl_g4_age12 repeatgirl_g5_age12 repeatgirl_g6_age12 repeaters_pre_age13 repeaters_g1_age13 repeaters_g2_age13 repeaters_g3_age13 repeaters_g4_age13 repeaters_g5_age13 repeaters_g6_age13 repeatgirl_pre_age13 repeatgirl_g1_age13 repeatgirl_g2_age13 repeatgirl_g3_age13 repeatgirl_g4_age13 repeatgirl_g5_age13 repeatgirl_g6_age13 repeaters_pre_age14 repeaters_g1_age14 repeaters_g2_age14 repeaters_g3_age14 repeaters_g4_age14 repeaters_g5_age14 repeaters_g6_age14 repeatgirl_pre_age14 repeatgirl_g1_age14 repeatgirl_g2_age14 repeatgirl_g3_age14 repeatgirl_g4_age14 repeatgirl_g5_age14 repeatgirl_g6_age14, after(repeatgirl)
order nivprof_mf_6_ini_1 nivprof_f_6_ini_1 nivprof_mf_7_ini_1 nivprof_mf_7_ini_2 nivprof_f_7_ini_1 nivprof_f_7_ini_2 nivprof_mf_10_ini_1 nivprof_mf_10_ini_2 nivprof_f_10_ini_1 nivprof_f_10_ini_2 nivprof_mf_12_ini_1 nivprof_mf_12_ini_2 nivprof_f_12_ini_1 nivprof_f_12_ini_2 nivprof_mf_bach_ini_1 nivprof_f_bach_ini_1 nivprof_mf_lic_ini_1 nivprof_f_lic_ini_1 nivprof_mf_6_1 nivprof_f_6_1 nivprof_mf_7_1 nivprof_mf_7_2 nivprof_f_7_1 nivprof_f_7_2 nivprof_mf_10_1 nivprof_mf_10_2 nivprof_f_10_1 nivprof_f_10_2 nivprof_mf_12_1 nivprof_mf_12_2 nivprof_f_12_1 nivprof_f_12_2 nivprof_mf_bach_1 nivprof_f_bach_1 nivprof_mf_lic_1 nivprof_f_lic_1, after(nivprof_f_lic_2)
order desks_ind1 desks_ind2 desks_double1 desks_double2 desks_double3 seats_ind1 seats_ind2 seats_double1 seats_double2 seats_double3, after(seats)
order manu_teacher_pre_4 manu_teacher_pre_6 manu_teacher_pre_7 manu_teacher_pre_8 manu_teacher_pre_9 manu_teacher_pre_10 manu_teacher_pre_11 manu_student_pre_4 manu_student_pre_6 manu_student_pre_7 manu_student_pre_8 manu_student_pre_9 manu_student_pre_10 manu_student_pre_11 manu_teacher_g1_4 manu_teacher_g1_6 manu_teacher_g1_7 manu_teacher_g1_8 manu_teacher_g1_9 manu_teacher_g1_10 manu_teacher_g1_11 manu_student_g1_4 manu_student_g1_6 manu_student_g1_7 manu_student_g1_8 manu_student_g1_9 manu_student_g1_10 manu_student_g1_11 manu_teacher_g2_4 manu_teacher_g2_6 manu_teacher_g2_7 manu_teacher_g2_8 manu_teacher_g2_9 manu_teacher_g2_10 manu_teacher_g2_11 manu_student_g2_4 manu_student_g2_6 manu_student_g2_7 manu_student_g2_8 manu_student_g2_9 manu_student_g2_10 manu_student_g2_11 manu_teacher_g3_4 manu_teacher_g3_6 manu_teacher_g3_7 manu_teacher_g3_8 manu_teacher_g3_9 manu_teacher_g3_10 manu_teacher_g3_11 manu_student_g3_4 manu_student_g3_6 manu_student_g3_7 manu_student_g3_8 manu_student_g3_9 manu_student_g3_10 manu_student_g3_11 manu_teacher_g4_4 manu_teacher_g4_6 manu_teacher_g4_7 manu_teacher_g4_8 manu_teacher_g4_9 manu_teacher_g4_10 manu_teacher_g4_11 manu_student_g4_4 manu_student_g4_6 manu_student_g4_7 manu_student_g4_8 manu_student_g4_9 manu_student_g4_10 manu_student_g4_11 manu_teacher_g5_4 manu_teacher_g5_6 manu_teacher_g5_7 manu_teacher_g5_8 manu_teacher_g5_9 manu_teacher_g5_10 manu_teacher_g5_11 manu_student_g5_4 manu_student_g5_6 manu_student_g5_7 manu_student_g5_8 manu_student_g5_9 manu_student_g5_10 manu_student_g5_11 manu_teacher_g6_4 manu_teacher_g6_6 manu_teacher_g6_7 manu_teacher_g6_8 manu_teacher_g6_9 manu_teacher_g6_10 manu_teacher_g6_11 manu_student_g6_4 manu_student_g6_6 manu_student_g6_7 manu_student_g6_8 manu_student_g6_9 manu_student_g6_10 manu_student_g6_11, after(manu_student_g6_12)
order sportfields libraries computerrooms computerlabs bathrooms canteens, after(bathroom)

replace school_id=112 if school_name=="Sanga                         "

egen teachers = rowtotal(teachers_pre teachers_prim), missing
egen teachfem = rowtotal(teachfem_pre teachfem_prim), missing


* * * * * * * * * * * * * * * * * * * * * * * * * *

drop school_name number_periods period_hours morning_hours afternoon_hours night_hours

drop director_name director_age director_tel director_edu director_spec deputy_name deputy_edu deputy_spec director_hoursdir deputy_hoursdir director_hoursteach deputy_hoursteach

drop periods_pre periods_g1 periods_g2 periods_g3 periods_g4 periods_g5 periods_g6

order 	school_id 											/// School ID
		date_day date_month date_year						/// Date
		classes_pre classes_g1 classes_g2 classes_g3 		/// Classes
		classes_g4 classes_g5 classes_g6 classes			///
		students_pre students_g1 students_g2 students_g3 	/// Students
		students_g4 students_g5 students_g6 students		///
		girls_pre  girls_g1  girls_g2  girls_g3  girls_g4  	/// Female students
		girls_g5  girls_g6 girls							///
		repeaters_g1 repeaters_g2 repeaters_g3 repeaters_g4 /// Repeaters
		repeaters_g5 repeaters_g6 repeaters					///
		repeatgirl_g1 repeatgirl_g2 repeatgirl_g3 			/// Female repeaters
		repeatgirl_g4 repeatgirl_g5 repeatgirl_g6 			///
		repeatgirl											///
		disabled_pre disabled_g1 disabled_g2 disabled_g3 	/// Disabled students
		disabled_g4 disabled_g5 disabled_g6					///
		disabled_visual disabled_audio disabled_motor 		///
		disabled_other disabled								///
		disabgirl_pre disabgirl_g1 disabgirl_g2 			/// Female disabled students
		disabgirl_g3 disabgirl_g4 disabgirl_g5 				///
		disabgirl_g6 disabgirl_visual disabgirl_audio 		///
		disabgirl_motor disabgirl_other disabgirl			///
		teachers_pre teachers_prim teachers 				/// Teachers
		teachers_share_uni									///
		teachfem_pre teachfem_prim teachfem 				/// Female Teachers
		teachfem_share_uni									///
		secretaries guards cleaners other_teachers 			/// Staff
		other_empl											///
		secretaries_fem guards_fem cleaners_fem 			/// Female staff
		other_teachers_fem other_empl_fem					///
		classrooms_def_blocks classrooms_prov_blocks 		/// Classrooms
		classrooms_impr_blocks classrooms_def_cement 		///
		classrooms_prov_cement classrooms_impr_cement 		///
		classrooms_def_other classrooms_prov_other 			///
		classrooms_impr_other classrooms_def 				///
		classrooms_prov classrooms_impr classrooms			///
		desks seats chalkboards teacher_desks				/// Furniture
		highest_grade sportfield outside_classes 			/// Other characteristics
		bathroom canteen water electricity					///

drop version library students_pre_age5 students_g1_age5 students_g2_age5 students_g3_age5 students_g4_age5 students_g5_age5 students_g6_age5 girls_pre_age5 girls_g1_age5 girls_g2_age5 girls_g3_age5 girls_g4_age5 girls_g5_age5 girls_g6_age5 students_pre_age6 students_g1_age6 students_g2_age6 students_g3_age6 students_g4_age6 students_g5_age6 students_g6_age6 girls_pre_age6 girls_g1_age6 girls_g2_age6 girls_g3_age6 girls_g4_age6 girls_g5_age6 girls_g6_age6 students_pre_age7 students_g1_age7 students_g2_age7 students_g3_age7 students_g4_age7 students_g5_age7 students_g6_age7 girls_pre_age7 girls_g1_age7 girls_g2_age7 girls_g3_age7 girls_g4_age7 girls_g5_age7 girls_g6_age7 students_pre_age8 students_g1_age8 students_g2_age8 students_g3_age8 students_g4_age8 students_g5_age8 students_g6_age8 girls_pre_age8 girls_g1_age8 girls_g2_age8 girls_g3_age8 girls_g4_age8 girls_g5_age8 girls_g6_age8 students_pre_age9 students_g1_age9 students_g2_age9 students_g3_age9 students_g4_age9 students_g5_age9 students_g6_age9 girls_pre_age9 girls_g1_age9 girls_g2_age9 girls_g3_age9 girls_g4_age9 girls_g5_age9 girls_g6_age9 students_pre_age10 students_g1_age10 students_g2_age10 students_g3_age10 students_g4_age10 students_g5_age10 students_g6_age10 girls_pre_age10 girls_g1_age10 girls_g2_age10 girls_g3_age10 girls_g4_age10 girls_g5_age10 girls_g6_age10 students_pre_age11 students_g1_age11 students_g2_age11 students_g3_age11 students_g4_age11 students_g5_age11 students_g6_age11 girls_pre_age11 girls_g1_age11 girls_g2_age11 girls_g3_age11 girls_g4_age11 girls_g5_age11 girls_g6_age11 students_pre_age12 students_g1_age12 students_g2_age12 students_g3_age12 students_g4_age12 students_g5_age12 students_g6_age12 girls_pre_age12 girls_g1_age12 girls_g2_age12 girls_g3_age12 girls_g4_age12 girls_g5_age12 girls_g6_age12 students_pre_age13 students_g1_age13 students_g2_age13 students_g3_age13 students_g4_age13 students_g5_age13 students_g6_age13 girls_pre_age13 girls_g1_age13 girls_g2_age13 girls_g3_age13 girls_g4_age13 girls_g5_age13 girls_g6_age13 students_pre_age14 students_g1_age14 students_g2_age14 students_g3_age14 students_g4_age14 students_g5_age14 students_g6_age14 girls_pre_age14 girls_g1_age14 girls_g2_age14 girls_g3_age14 girls_g4_age14 girls_g5_age14 girls_g6_age14 repeaters_pre_age5 repeaters_g1_age5 repeaters_g2_age5 repeaters_g3_age5 repeaters_g4_age5 repeaters_g5_age5 repeaters_g6_age5 repeatgirl_pre_age5 repeatgirl_g1_age5 repeatgirl_g2_age5 repeatgirl_g3_age5 repeatgirl_g4_age5 repeatgirl_g5_age5 repeatgirl_g6_age5 repeaters_pre_age6 repeaters_g1_age6 repeaters_g2_age6 repeaters_g3_age6 repeaters_g4_age6 repeaters_g5_age6 repeaters_g6_age6 repeatgirl_pre_age6 repeatgirl_g1_age6 repeatgirl_g2_age6 repeatgirl_g3_age6 repeatgirl_g4_age6 repeatgirl_g5_age6 repeatgirl_g6_age6 repeaters_pre_age7 repeaters_g1_age7 repeaters_g2_age7 repeaters_g3_age7 repeaters_g4_age7 repeaters_g5_age7 repeaters_g6_age7 repeatgirl_pre_age7 repeatgirl_g1_age7 repeatgirl_g2_age7 repeatgirl_g3_age7 repeatgirl_g4_age7 repeatgirl_g5_age7 repeatgirl_g6_age7 repeaters_pre_age8 repeaters_g1_age8 repeaters_g2_age8 repeaters_g3_age8 repeaters_g4_age8 repeaters_g5_age8 repeaters_g6_age8 repeatgirl_pre_age8 repeatgirl_g1_age8 repeatgirl_g2_age8 repeatgirl_g3_age8 repeatgirl_g4_age8 repeatgirl_g5_age8 repeatgirl_g6_age8 repeaters_pre_age9 repeaters_g1_age9 repeaters_g2_age9 repeaters_g3_age9 repeaters_g4_age9 repeaters_g5_age9 repeaters_g6_age9 repeatgirl_pre_age9 repeatgirl_g1_age9 repeatgirl_g2_age9 repeatgirl_g3_age9 repeatgirl_g4_age9 repeatgirl_g5_age9 repeatgirl_g6_age9 repeaters_pre_age10 repeaters_g1_age10 repeaters_g2_age10 repeaters_g3_age10 repeaters_g4_age10 repeaters_g5_age10 repeaters_g6_age10 repeatgirl_pre_age10 repeatgirl_g1_age10 repeatgirl_g2_age10 repeatgirl_g3_age10 repeatgirl_g4_age10 repeatgirl_g5_age10 repeatgirl_g6_age10 repeaters_pre_age11 repeaters_g1_age11 repeaters_g2_age11 repeaters_g3_age11 repeaters_g4_age11 repeaters_g5_age11 repeaters_g6_age11 repeatgirl_pre_age11 repeatgirl_g1_age11 repeatgirl_g2_age11 repeatgirl_g3_age11 repeatgirl_g4_age11 repeatgirl_g5_age11 repeatgirl_g6_age11 repeaters_pre_age12 repeaters_g1_age12 repeaters_g2_age12 repeaters_g3_age12 repeaters_g4_age12 repeaters_g5_age12 repeaters_g6_age12 repeatgirl_pre_age12 repeatgirl_g1_age12 repeatgirl_g2_age12 repeatgirl_g3_age12 repeatgirl_g4_age12 repeatgirl_g5_age12 repeatgirl_g6_age12 repeaters_pre_age13 repeaters_g1_age13 repeaters_g2_age13 repeaters_g3_age13 repeaters_g4_age13 repeaters_g5_age13 repeaters_g6_age13 repeatgirl_pre_age13 repeatgirl_g1_age13 repeatgirl_g2_age13 repeatgirl_g3_age13 repeatgirl_g4_age13 repeatgirl_g5_age13 repeatgirl_g6_age13 repeaters_pre_age14 repeaters_g1_age14 repeaters_g2_age14 repeaters_g3_age14 repeaters_g4_age14 repeaters_g5_age14 repeaters_g6_age14 repeatgirl_pre_age14 repeatgirl_g1_age14 repeatgirl_g2_age14 repeatgirl_g3_age14 repeatgirl_g4_age14 repeatgirl_g5_age14 repeatgirl_g6_age14 disabled_visual_pre disabled_visual_g1 disabled_visual_g2 disabled_visual_g3 disabled_visual_g4 disabled_visual_g5 disabled_visual_g6 disabgirl_visual_pre disabgirl_visual_g1 disabgirl_visual_g2 disabgirl_visual_g3 disabgirl_visual_g4 disabgirl_visual_g5 disabgirl_visual_g6 disabled_audio_pre disabled_audio_g1 disabled_audio_g2 disabled_audio_g3 disabled_audio_g4 disabled_audio_g5 disabled_audio_g6 disabgirl_audio_pre disabgirl_audio_g1 disabgirl_audio_g2 disabgirl_audio_g3 disabgirl_audio_g4 disabgirl_audio_g5 disabgirl_audio_g6 disabled_motor_pre disabled_motor_g1 disabled_motor_g2 disabled_motor_g3 disabled_motor_g4 disabled_motor_g5 disabled_motor_g6 disabgirl_motor_pre disabgirl_motor_g1 disabgirl_motor_g2 disabgirl_motor_g3 disabgirl_motor_g4 disabgirl_motor_g5 disabgirl_motor_g6 disabled_other_pre disabled_other_g1 disabled_other_g2 disabled_other_g3 disabled_other_g4 disabled_other_g5 disabled_other_g6 disabgirl_other_pre disabgirl_other_g1 disabgirl_other_g2 disabgirl_other_g3 disabgirl_other_g4 disabgirl_other_g5 disabgirl_other_g6 nivprof_mf_6_ini nivprof_mf_6_ini_2 nivprof_f_6_ini nivprof_f_6_ini_2 nivprof_mf_7x_ini nivprof_mf_7x_ini_2 nivprof_f_7x_ini nivprof_f_7x_ini_2 nivprof_mf_9_ini nivprof_mf_9_ini_2 nivprof_f_9_ini nivprof_f_9_ini_2 nivprof_mf_11_ini nivprof_mf_11_ini_2 nivprof_f_11_ini nivprof_f_11_ini_2 nivprof_mf_bach_ini nivprof_mf_bach_ini_2 nivprof_f_bach_ini nivprof_f_bach_ini_2 nivprof_mf_lic_ini nivprof_mf_lic_ini_2 nivprof_f_lic_ini nivprof_f_lic_ini_2 nivprof_mf_6 nivprof_mf_6_2 nivprof_f_6 nivprof_f_6_2 nivprof_mf_7x nivprof_mf_7x_2 nivprof_f_7x nivprof_f_7x_2 nivprof_mf_9 nivprof_mf_9_2 nivprof_f_9 nivprof_f_9_2 nivprof_mf_11 nivprof_mf_11_2 nivprof_f_11 nivprof_f_11_2 nivprof_mf_bach nivprof_mf_bach_2 nivprof_f_bach nivprof_f_bach_2 nivprof_mf_lic nivprof_mf_lic_2 nivprof_f_lic nivprof_f_lic_2 nivprof_mf_6_ini_1 nivprof_f_6_ini_1 nivprof_mf_7_ini_1 nivprof_mf_7_ini_2 nivprof_f_7_ini_1 nivprof_f_7_ini_2 nivprof_mf_10_ini_1 nivprof_mf_10_ini_2 nivprof_f_10_ini_1 nivprof_f_10_ini_2 nivprof_mf_12_ini_1 nivprof_mf_12_ini_2 nivprof_f_12_ini_1 nivprof_f_12_ini_2 nivprof_mf_bach_ini_1 nivprof_f_bach_ini_1 nivprof_mf_lic_ini_1 nivprof_f_lic_ini_1 nivprof_mf_6_1 nivprof_f_6_1 nivprof_mf_7_1 nivprof_mf_7_2 nivprof_f_7_1 nivprof_f_7_2 nivprof_mf_10_1 nivprof_mf_10_2 nivprof_f_10_1 nivprof_f_10_2 nivprof_mf_12_1 nivprof_mf_12_2 nivprof_f_12_1 nivprof_f_12_2 nivprof_mf_bach_1 nivprof_f_bach_1 nivprof_mf_lic_1 nivprof_f_lic_1 teachers_age18_pre teachers_age20_pre teachers_age25_pre teachers_age30_pre teachers_age35_pre teachers_age40_pre teachfem_age18_pre teachfem_age20_pre teachfem_age25_pre teachfem_age30_pre teachfem_age35_pre teachfem_age40_pre teachers_age18_prim teachers_age20_prim teachers_age25_prim teachers_age30_prim teachers_age35_prim teachers_age40_prim teachfem_age18_prim teachfem_age20_prim teachfem_age25_prim teachfem_age30_prim teachfem_age35_prim teachfem_age40_prim desks_ind desks_double desks_more seats_ind seats_double seats_more desks_ind1 desks_ind2 desks_double1 desks_double2 desks_double3 seats_ind1 seats_ind2 seats_double1 seats_double2 seats_double3 manu_teacher_pre_1 manu_teacher_pre_2 manu_teacher_pre_3 manu_teacher_pre_5 manu_teacher_pre_12 manu_student_pre_1 manu_student_pre_2 manu_student_pre_3 manu_student_pre_5 manu_student_pre_12 manu_teacher_g1_1 manu_teacher_g1_2 manu_teacher_g1_3 manu_teacher_g1_5 manu_teacher_g1_12 manu_student_g1_1 manu_student_g1_2 manu_student_g1_3 manu_student_g1_5 manu_student_g1_12 manu_teacher_g2_1 manu_teacher_g2_2 manu_teacher_g2_3 manu_teacher_g2_5 manu_teacher_g2_12 manu_student_g2_1 manu_student_g2_2 manu_student_g2_3 manu_student_g2_5 manu_student_g2_12 manu_teacher_g3_1 manu_teacher_g3_2 manu_teacher_g3_3 manu_teacher_g3_5 manu_teacher_g3_12 manu_student_g3_1 manu_student_g3_2 manu_student_g3_3 manu_student_g3_5 manu_student_g3_12 manu_teacher_g4_1 manu_teacher_g4_2 manu_teacher_g4_3 manu_teacher_g4_5 manu_teacher_g4_12 manu_student_g4_1 manu_student_g4_2 manu_student_g4_3 manu_student_g4_5 manu_student_g4_12 manu_teacher_g5_1 manu_teacher_g5_2 manu_teacher_g5_3 manu_teacher_g5_5 manu_teacher_g5_12 manu_student_g5_1 manu_student_g5_2 manu_student_g5_3 manu_student_g5_5 manu_student_g5_12 manu_teacher_g6_1 manu_teacher_g6_2 manu_teacher_g6_3 manu_teacher_g6_5 manu_teacher_g6_12 manu_student_g6_1 manu_student_g6_2 manu_student_g6_3 manu_student_g6_5 manu_student_g6_12 manu_teacher_pre_4 manu_teacher_pre_6 manu_teacher_pre_7 manu_teacher_pre_8 manu_teacher_pre_9 manu_teacher_pre_10 manu_teacher_pre_11 manu_student_pre_4 manu_student_pre_6 manu_student_pre_7 manu_student_pre_8 manu_student_pre_9 manu_student_pre_10 manu_student_pre_11 manu_teacher_g1_4 manu_teacher_g1_6 manu_teacher_g1_7 manu_teacher_g1_8 manu_teacher_g1_9 manu_teacher_g1_10 manu_teacher_g1_11 manu_student_g1_4 manu_student_g1_6 manu_student_g1_7 manu_student_g1_8 manu_student_g1_9 manu_student_g1_10 manu_student_g1_11 manu_teacher_g2_4 manu_teacher_g2_6 manu_teacher_g2_7 manu_teacher_g2_8 manu_teacher_g2_9 manu_teacher_g2_10 manu_teacher_g2_11 manu_student_g2_4 manu_student_g2_6 manu_student_g2_7 manu_student_g2_8 manu_student_g2_9 manu_student_g2_10 manu_student_g2_11 manu_teacher_g3_4 manu_teacher_g3_6 manu_teacher_g3_7 manu_teacher_g3_8 manu_teacher_g3_9 manu_teacher_g3_10 manu_teacher_g3_11 manu_student_g3_4 manu_student_g3_6 manu_student_g3_7 manu_student_g3_8 manu_student_g3_9 manu_student_g3_10 manu_student_g3_11 manu_teacher_g4_4 manu_teacher_g4_6 manu_teacher_g4_7 manu_teacher_g4_8 manu_teacher_g4_9 manu_teacher_g4_10 manu_teacher_g4_11 manu_student_g4_4 manu_student_g4_6 manu_student_g4_7 manu_student_g4_8 manu_student_g4_9 manu_student_g4_10 manu_student_g4_11 manu_teacher_g5_4 manu_teacher_g5_6 manu_teacher_g5_7 manu_teacher_g5_8 manu_teacher_g5_9 manu_teacher_g5_10 manu_teacher_g5_11 manu_student_g5_4 manu_student_g5_6 manu_student_g5_7 manu_student_g5_8 manu_student_g5_9 manu_student_g5_10 manu_student_g5_11 manu_teacher_g6_4 manu_teacher_g6_6 manu_teacher_g6_7 manu_teacher_g6_8 manu_teacher_g6_9 manu_teacher_g6_10 manu_teacher_g6_11 manu_student_g6_4 manu_student_g6_6 manu_student_g6_7 manu_student_g6_8 manu_student_g6_9 manu_student_g6_10 manu_student_g6_11 sportfields libraries computerrooms computerlabs bathrooms canteens

rename * A17_*
rename A17_school_id school_id

save "$Endline_dtRaw/_intermediate files/admin17.dta", replace




********************************************************************************
********************************************************************************




// 2018

use "$Endline_dtRaw/admin/escolas18.dta", clear

label variable escola_id "School ID"
label variable nome_da_escola "School name"
label variable director "School director name"
label variable idade_director "Director age"
label variable nivel_academico_d "Director education"
label variable n_de_telefone "Director phone number"
label variable especialidade_d "Director speciality"
lab var n_de_horas_como_docente_d "Director number of hours teacher"
lab var n_de_horas_como_director_d "Director number of hours director"
label variable nome_do_sub_director_pedagogico "Deputy director name"
label variable idade_sd "Deputy director age"
label variable nivel_academico_sd "Deputy director education"
label variable n_de_telefone_sd "Deputy director phone number"
label variable especialidade_sd "Deputy director speciality"
label variable n_de_horas_como_docente_sd "Deputy director number of hours teacher"
label variable n_de_horas_como_director_sd "Deputy director number of hours director"
label variable regime_de_ensino "Type of school"

drop clube_hiv merenda tem_gab_de_apoio_p latitude longitude

lab var salas_para_professsores "Number of teacher rooms"
lab var salas_da_escola_para_alunos  "Number of classrooms"
lab var turmas_mistas  "Number of mixed classes"
lab var turmas_no_ar_livre  "Number of classes outside"
lab var quadros_didaticos_utilizados  "Number of chalkboards"
lab var numero_de_secretarias_para_docen  "Number of teacher desks"
lab var n_de_assentos_para_alunos_luga  "Number of places for students"
lab var n_de_carteiras "Number of seats/desks"

rename escola_id 							school_id
rename regime_de_ensino  					school_type
rename nome_da_escola  						school_name
rename director  				 			director_name
rename idade_director  						director_age
rename n_de_telefone  						director_tel
rename nivel_academico_d  					director_edu
rename especialidade_d  					director_spec
rename nome_do_sub_director_pedagogico  	deputy_name
rename nivel_academico_sd  					deputy_edu
rename especialidade_sd  					deputy_spec
rename n_de_horas_como_director_d  			director_hoursdir
rename n_de_horas_como_director_sd  		deputy_hoursdir
rename n_de_horas_como_docente_d  			director_hoursteach
rename n_de_horas_como_docente_sd  			deputy_hoursteach
rename idade_sd  							deputy_age
rename n_de_telefone_sd  					deputy_tel
rename salas_para_professsores 				rooms_teacher
rename salas_da_escola_para_alunos  		classrooms2
rename turmas_mistas  						classes_mixed
rename turmas_no_ar_livre  					classes_outside
rename quadros_didaticos_utilizados  		chalkboards
rename numero_de_secretarias_para_docen  	desks_teacher
rename n_de_assentos_para_alunos_luga  		places_students
rename n_de_carteiras						seats_desks_students

replace director_name = "" if director_name=="999"
replace director_age = . if director_age==99
replace director_tel = . if director_tel==999
replace director_hoursteach = . if director_hoursteach==99
replace director_hoursdir = . if director_hoursdir==99


replace deputy_name = "" if director_name=="999"
replace deputy_age = . if director_age==99
replace deputy_tel = . if director_tel==999
replace deputy_hoursteach = . if director_hoursteach==99
replace deputy_hoursdir = . if director_hoursdir==99

replace school_type = . if school_type==9

foreach var in rooms_teacher classrooms2 classes_mixed classes_outside chalkboards desks_teacher{
replace `var' = . if `var' == 99
}
replace places_students = . if places_students==999
replace seats_desks_students = . if seats_desks_students==999

label variable salas_def_1 "Number of classrooms: definite structure, prefrabricated blocks"
label variable salas_prov_1 "Number of classrooms: provisional structure, prefrabricated blocks"
label variable salas_impr_1 "Number of classrooms: improvised structure, prefrabricated blocks"

label variable salas_def_2 "Number of classrooms: definite structure, cement or bricks"
label variable salas_prov_2 "Number of classrooms: provisional structure, cement or bricks"
label variable salas_impr_2 "Number of classrooms: improvised structure, cement or bricks"

label variable salas_def_3 "Number of classrooms: definite structure, other materials"
label variable salas_prov_3 "Number of classrooms: provisional structure, other materials"
label variable salas_impr_3 "Number of classrooms: improvised structure, other materials"


rename salas_def_1 		classrooms_def_blocks
rename salas_prov_1 	classrooms_prov_blocks
rename salas_impr_1 	classrooms_impr_blocks

rename salas_def_2 	classrooms_def_cement
rename salas_prov_2 	classrooms_prov_cement
rename salas_impr_2 	classrooms_impr_cement

rename salas_def_3 	classrooms_def_other
rename salas_prov_3 	classrooms_prov_other
rename salas_impr_3	classrooms_impr_other

foreach var in classrooms_def_blocks classrooms_def_cement classrooms_def_other ///
	classrooms_prov_blocks classrooms_prov_cement classrooms_prov_other 	///
	classrooms_impr_blocks classrooms_impr_cement classrooms_impr_other{
replace `var' = . if `var' == 99
}

egen classrooms_def = rowtotal(classrooms_def_blocks classrooms_def_cement classrooms_def_other), missing
egen classrooms_prov = rowtotal(classrooms_prov_blocks classrooms_prov_cement classrooms_prov_other), missing
egen classrooms_impr = rowtotal(classrooms_impr_blocks classrooms_impr_cement classrooms_impr_other), missing

egen classrooms = rowtotal(classrooms_def classrooms_prov classrooms_impr), missing

lab var classrooms_def 		"Number of classrooms with definite structure"
lab var classrooms_prov 	"Number of classrooms with provisional structure"
lab var classrooms_impr		"Number of classrooms with improvised structure"
lab var classrooms 			"Number of classrooms in total"

order classrooms_def classrooms_prov classrooms_impr classrooms, after(classrooms_impr_other)


label variable salas_def_anex_1 "Number of annex classrooms: definite structure, prefrabricated blocks"
label variable salas_prov_anex_1 "Number of annex classrooms: provisional structure, prefrabricated blocks"
label variable salas_impr_anex_1 "Number of annex classrooms: improvised structure, prefrabricated blocks"

label variable salas_def_anex_2 "Number of annex classrooms: definite structure, cement or bricks"
label variable salas_prov_anex_2 "Number of annex classrooms: provisional structure, cement or bricks"
label variable salas_impr_anex_2 "Number of annex classrooms: improvised structure, cement or bricks"

label variable salas_def_anex_3 "Number of annex classrooms: definite structure, other materials"
label variable salas_prov_anex_3 "Number of annex classrooms: provisional structure, other materials"
label variable salas_impr_anex_3 "Number of annex classrooms: improvised structure, other materials"

rename salas_def_anex_1 	classrooms_annex_def_blocks
rename salas_prov_anex_1 	classrooms_annex_prov_blocks
rename salas_impr_anex_1 	classrooms_annex_impr_blocks

rename salas_def_anex_2 	classrooms_annex_def_cement
rename salas_prov_anex_2 	classrooms_annex_prov_cement
rename salas_impr_anex_2 	classrooms_annex_impr_cement

rename salas_def_anex_3 	classrooms_annex_def_other
rename salas_prov_anex_3 	classrooms_annex_prov_other
rename salas_impr_anex_3	classrooms_annex_impr_other

egen classrooms_annex_def = rowtotal(classrooms_annex_def_blocks classrooms_annex_def_cement classrooms_annex_def_other), missing
egen classrooms_annex_prov = rowtotal(classrooms_annex_prov_blocks classrooms_annex_prov_cement classrooms_annex_prov_other), missing
egen classrooms_annex_impr = rowtotal(classrooms_annex_impr_blocks classrooms_annex_impr_cement classrooms_annex_impr_other), missing

egen classrooms_annex = rowtotal(classrooms_annex_def classrooms_annex_prov classrooms_annex_impr), missing

gen classrooms_plusannex = classrooms + classrooms_annex

lab var classrooms_annex_def 		"Number of annex classrooms with definite structure"
lab var classrooms_annex_prov 	"Number of annex classrooms with provisional structure"
lab var classrooms_annex_impr		"Number of annex classrooms with improvised structure"
lab var classrooms_annex 		"Number of annex classrooms in total"
lab var classrooms_plusannex 		"Number of classrooms in total (both normal and annex)"

order classrooms_annex_def classrooms_annex_prov classrooms_annex_impr classrooms_annex classrooms_plusannex, after(classrooms_annex_impr_other)

label variable aux_mf_1 "Number of admin teachers"
label variable aux_mf_2 "Number of secretaries"
label variable aux_mf_3 "Number of guards"
label variable aux_mf_4 "Number of cleaning staff"
label variable aux_mf_5 "Number of other employees"

label variable aux_f_1 "Number of female admin teachers"
label variable aux_f_2 "Number of female secretaries"
label variable aux_f_3 "Number of female guards"
label variable aux_f_4 "Number of female cleaning assistants"
label variable aux_f_5 "Number of female other employees"

rename aux_mf_1 other_teachers
rename aux_mf_2 secretaries
rename aux_mf_3 guards
rename aux_mf_4 cleaners
rename aux_mf_5 other_empl
rename aux_f_1  other_teachers_fem
rename aux_f_2  secretaries_fem
rename aux_f_3  guards_fem
rename aux_f_4  cleaners_fem
rename aux_f_5  other_empl_fem

label variable prof_nac_1 		"Teachers (Angolan) with pedagogical training"
label variable prof_estr_1		"Teachers (foreign) with pedagogical training"

label variable prof_nac_2 		"Teachers (Angolan) without pedagogical training"
label variable prof_estr_2		"Teachers (foreign) without pedagogical training"

label variable prof_nac_4 		"Teachers (Angolan) with PAT training"
label variable prof_estr_4		"Teachers (foreign) with PAT training"

drop prof_nac_3 prof_estr_3

rename prof_nac_1 	teachers_ang_pedag
rename prof_nac_2 	teachers_ang_nopedag
rename prof_nac_4  	teachers_ang_pat

rename prof_estr_1  teachers_for_pedag
rename prof_estr_2  teachers_for_nopedag
rename prof_estr_4	teachers_for_pat


drop teachers_ang_pedag teachers_ang_nopedag teachers_ang_pat teachers_for_pedag teachers_for_nopedag teachers_for_pat

drop do_projecto do_projecto_last numero_organismo

rename	campo_para_desporto	sportfield
rename	casa_de_banho_para_alunos_total	bathrooms_students
rename	casa_de_banho_para_rapazes	bathrooms_boys
rename	casa_de_banho_para_raparigas	bathrooms_girls
rename	casa_de_banho_para_profs_total	bathrooms_teachers
rename	casa_de_banho_para_profs_h	bathrooms_men
rename	casa_de_banho_para_profs_m	bathrooms_women
rename	asesso_a_agua_potavel_sim_nao	water
rename	asesso_a_electricidade_sim_nao	electricity
rename	cantina_escolar_sim_nao	canteen
rename	numero_de_computadores_na_escola	computers
rename	pc_prof	computers_teachers
rename	pc_alunos	computers_students
rename	tem_ligacao_internnet_na_escola	internet
rename	numero_de_projectores	projectors
rename	numero_de_casas_total	houses
rename	casas_prof	houses_teachers
rename	casas_dir	hourses_director
rename	de_aguas_risiduais	residualwater_deposit
rename	de_risdues_solidos_lixo	waste_deposit
rename	euipamento_do_pat_sim_nao	pat_material
rename	proj_educativo_escolar_do_pat	pat
rename	numero_da_zip_a_que_pertence	zip
rename	centro_de_recursos_sn	supply_center
rename	ultima_classe_ensinada_na_escola	highest_grade
rename	ano_de_inicio_de_fuuncionamento	establishment_year
rename	distancia_ao_centro_de_ra	distance_supply_center
rename	distancia_a_repatricao_municipal	distance_municipal_center
rename	distancia_a_direcao_provincial	distance_provincial_center
rename	tem_comissao_de_pais	parents_committee
rename	a_comissao_funcionou_no_ano_ante	parents_committee_active
rename	tem_assembleia_de_escolas	school_assembly
rename	a_assembleia_funcionou_no_ano_an	school_assembly_active

lab var sportfield "Sportfield at the school"
lab var bathrooms_students "Number of bathrooms students"
lab var bathrooms_boys "Number of bathrooms boys"
lab var bathrooms_girls "Number of bathrooms girls"
lab var bathrooms_teachers "Number of bathrooms teachers"
lab var bathrooms_men "Number of bathrooms men"
lab var bathrooms_women "Number of bathrooms women"
lab var water "Water at the school"
lab var electricity "Electricity at the school"
lab var canteen "Canteen at the school"
lab var computers "Comuters at the school"
lab var computers_teachers "Comuters for teachers at the school"
lab var computers_students "Comuters  for students at the school"
lab var internet "Internet at the school"
lab var projectors "Projectors at the school"
lab var houses "Houses for staff"
lab var houses_teachers "Houses for teachers"
lab var hourses_director "Houses for directors"
lab var residualwater_deposit "Residual water deposit at the school"
lab var waste_deposit "Waste deposit at the school"
lab var pat_material "Teacher training material"
lab var pat "Teacher training project"
lab var zip "Teacher association number"
lab var supply_center "Supply center affiliation"
lab var highest_grade "Highest class taught"
lab var establishment_year "Year of establishment school"
lab var distance_supply_center "Distance to the supply center"
lab var distance_municipal_center "Distance to the minicipal center"
lab var distance_provincial_center "Distance to the provincial center (Sumbe)"
lab var parents_committee "Parent committee at the school"
lab var parents_committee_active "Parent committee active"
lab var school_assembly "School assembly at the school"
lab var school_assembly_active "School assembly active"

replace bathrooms_girls = . if bathrooms_girls==99
replace bathrooms_women = . if bathrooms_women==99
replace zip = . if inlist(zip,99,999)
replace supply_center = . if supply_center==9
replace establishment_year = . if inlist(establishment_year,0,99,999)
replace parents_committee = . if parents_committee==9
replace parents_committee_active = . if parents_committee_active==9
replace school_assembly = . if school_assembly==9
replace school_assembly_active = . if school_assembly_active==9


drop pre_mf_6 pre_f_6 pre_mf_7 pre_f_7 pre_mf_8 pre_f_8 pre_mf_9 pre_f_9 pre_mf_10 pre_f_10

rename pre_mf_5 students_pre
rename pre_f_5 girls_pre

rename pre_rep_mf repeaters_pre
rename pre_rep_f repeatgirl_pre

replace pre_turmas_t=0 if pre_turmas_t==99
gen classes_pre = pre_turmas_m + pre_turmas_t

drop pre_turmas_m pre_turnos_m pre_turmas_t pre_turnos_t pre_turmas_n pre_turnos_n

egen disabled_pre = rowtotal(pre_nec_mf_vis pre_nec_mf_aud pre_nec_mf_mot pre_nec_mf_out), missing
egen disabgirl_pre = rowtotal(pre_nec_f_vis pre_nec_f_aud pre_nec_f_mot pre_nec_f_out), missing

egen teachers_pre_until13 = rowtotal(nivprof_mf_6_ini_1 nivprof_mf_6_ini_2 nivprof_mf_6_ini_3 nivprof_mf_78_ini_1 nivprof_mf_78_ini_2 nivprof_mf_78_ini_3 nivprof_mf_910_ini_1 nivprof_mf_910_ini_2 nivprof_mf_910_ini_3 nivprof_mf_111213_ini_1 nivprof_mf_111213_ini_2 nivprof_mf_111213_ini_3), missing
egen teachfem_pre_until13 = rowtotal(nivprof_f_6_ini_1 nivprof_f_6_ini_2 nivprof_f_6_ini_3 nivprof_f_78_ini_1 nivprof_f_78_ini_2 nivprof_f_78_ini_3 nivprof_f_910_ini_1 nivprof_f_910_ini_2 nivprof_f_910_ini_3 nivprof_f_111213_ini_1 nivprof_f_111213_ini_2 nivprof_f_111213_ini_3), missing

egen teachers_pre_uni = rowtotal(nivprof_mf_bach_ini_1 nivprof_mf_bach_ini_2 nivprof_mf_bach_ini_3 nivprof_mf_lic_ini_1 nivprof_mf_lic_ini_2 nivprof_mf_lic_ini_3 nivprof_mf_poslic_ini_1 nivprof_mf_poslic_ini_2 nivprof_mf_poslic_ini_3), missing
egen teachfem_pre_uni = rowtotal(nivprof_f_bach_ini_1 nivprof_f_bach_ini_2 nivprof_f_bach_ini_3 nivprof_f_lic_ini_1 nivprof_f_lic_ini_2 nivprof_f_lic_ini_3 nivprof_f_poslic_ini_1 nivprof_f_poslic_ini_2 nivprof_f_poslic_ini_3), missing

egen teachers_pre = rowtotal(teachers_pre_until13 teachers_pre_uni), missing
egen teachfem_pre = rowtotal(teachfem_pre_until13 teachfem_pre_uni), missing

drop nivprof_mf_6_ini_1 nivprof_mf_6_ini_2 nivprof_mf_6_ini_3 nivprof_mf_6_ini_4 nivprof_mf_6_ini_5 nivprof_f_6_ini_1 nivprof_f_6_ini_2 nivprof_f_6_ini_3 nivprof_f_6_ini_4 nivprof_f_6_ini_5 nivprof_mf_78_ini_1 nivprof_mf_78_ini_2 nivprof_mf_78_ini_3 nivprof_mf_78_ini_4 nivprof_mf_78_ini_5 nivprof_f_78_ini_1 nivprof_f_78_ini_2 nivprof_f_78_ini_3 nivprof_f_78_ini_4 nivprof_f_78_ini_5 nivprof_mf_910_ini_1 nivprof_mf_910_ini_2 nivprof_mf_910_ini_3 nivprof_mf_910_ini_4 nivprof_mf_910_ini_5 nivprof_f_910_ini_1 nivprof_f_910_ini_2 nivprof_f_910_ini_3 nivprof_f_910_ini_4 nivprof_f_910_ini_5 nivprof_mf_111213_ini_1 nivprof_mf_111213_ini_2 nivprof_mf_111213_ini_3 nivprof_mf_111213_ini_4 nivprof_mf_111213_ini_5 nivprof_f_111213_ini_1 nivprof_f_111213_ini_2 nivprof_f_111213_ini_3 nivprof_f_111213_ini_4 nivprof_f_111213_ini_5 nivprof_mf_bach_ini_1 nivprof_mf_bach_ini_2 nivprof_mf_bach_ini_3 nivprof_mf_bach_ini_4 nivprof_mf_bach_ini_5 nivprof_f_bach_ini_1 nivprof_f_bach_ini_2 nivprof_f_bach_ini_3 nivprof_f_bach_ini_4 nivprof_f_bach_ini_5 nivprof_mf_lic_ini_1 nivprof_mf_lic_ini_2 nivprof_mf_lic_ini_3 nivprof_mf_lic_ini_4 nivprof_mf_lic_ini_5 nivprof_f_lic_ini_1 nivprof_f_lic_ini_2 nivprof_f_lic_ini_3 nivprof_f_lic_ini_4 nivprof_f_lic_ini_5 nivprof_mf_poslic_ini_1 nivprof_mf_poslic_ini_2 nivprof_mf_poslic_ini_3 nivprof_mf_poslic_ini_4 nivprof_mf_poslic_ini_5 nivprof_f_poslic_ini_1 nivprof_f_poslic_ini_2 nivprof_f_poslic_ini_3 nivprof_f_poslic_ini_4 nivprof_f_poslic_ini_5

rename manu_prof_ini manu_teacher_pre
rename manu_alu_ini manu_student_pre

rename *1416* *14*

forval x=5/14{
lab var tot_mf_`x'_1 "Number of students grade 1 age `x'"
lab var tot_mf_`x'_2 "Number of students grade 2 age `x'"
lab var tot_mf_`x'_3 "Number of students grade 3 age `x'"
lab var tot_mf_`x'_4 "Number of students grade 4 age `x'"
lab var tot_mf_`x'_5 "Number of students grade 5 age `x'"
lab var tot_mf_`x'_6 "Number of students grade 6 age `x'"

lab var tot_f_`x'_1 "Number of girls grade 1 age `x'"
lab var tot_f_`x'_2 "Number of girls grade 2 age `x'"
lab var tot_f_`x'_3 "Number of girls grade 3 age `x'"
lab var tot_f_`x'_4 "Number of girls grade 4 age `x'"
lab var tot_f_`x'_5 "Number of girls grade 5 age `x'"
lab var tot_f_`x'_6 "Number of girls grade 6 age `x'"
}

rename tot_mf_(#)_1 students_g1_age(#)
rename tot_mf_(#)_2 students_g2_age(#)
rename tot_mf_(#)_3 students_g3_age(#)
rename tot_mf_(#)_4 students_g4_age(#)
rename tot_mf_(#)_5 students_g5_age(#)
rename tot_mf_(#)_6 students_g6_age(#)

rename tot_mf_(##)_1 students_g1_age(##)
rename tot_mf_(##)_2 students_g2_age(##)
rename tot_mf_(##)_3 students_g3_age(##)
rename tot_mf_(##)_4 students_g4_age(##)
rename tot_mf_(##)_5 students_g5_age(##)
rename tot_mf_(##)_6 students_g6_age(##)

rename tot_f_(#)_1 girls_g1_age(#)
rename tot_f_(#)_2 girls_g2_age(#)
rename tot_f_(#)_3 girls_g3_age(#)
rename tot_f_(#)_4 girls_g4_age(#)
rename tot_f_(#)_5 girls_g5_age(#)
rename tot_f_(#)_6 girls_g6_age(#)

rename tot_f_(##)_1 girls_g1_age(##)
rename tot_f_(##)_2 girls_g2_age(##)
rename tot_f_(##)_3 girls_g3_age(##)
rename tot_f_(##)_4 girls_g4_age(##)
rename tot_f_(##)_5 girls_g5_age(##)
rename tot_f_(##)_6 girls_g6_age(##)

destring students_g1_age10, replace

forval x=1/6{
egen students_g`x' = rowtotal(students_g`x'_age5 students_g`x'_age6 students_g`x'_age7 students_g`x'_age8 students_g`x'_age9 students_g`x'_age10 students_g`x'_age11 students_g`x'_age12 students_g`x'_age13 students_g`x'_age14), missing
egen girls_g`x' = rowtotal(girls_g`x'_age5 girls_g`x'_age6 girls_g`x'_age7 girls_g`x'_age8 girls_g`x'_age9 girls_g`x'_age10 girls_g`x'_age11 girls_g`x'_age12 girls_g`x'_age13 girls_g`x'_age14), missing
}

egen students = rowtotal(students_pre students_g1 students_g2 students_g3 students_g4 students_g5 students_g6), missing
egen girls = rowtotal(girls_pre girls_g1 girls_g2 girls_g3 girls_g4 girls_g5 girls_g6), missing


forval x=5/14{
lab var rep_mf_`x'_1 "Number of students grade 1 age `x'"
lab var rep_mf_`x'_2 "Number of students grade 2 age `x'"
lab var rep_mf_`x'_3 "Number of students grade 3 age `x'"
lab var rep_mf_`x'_4 "Number of students grade 4 age `x'"
lab var rep_mf_`x'_5 "Number of students grade 5 age `x'"
lab var rep_mf_`x'_6 "Number of students grade 6 age `x'"

lab var rep_f_`x'_1 "Number of girls grade 1 age `x'"
lab var rep_f_`x'_2 "Number of girls grade 2 age `x'"
lab var rep_f_`x'_3 "Number of girls grade 3 age `x'"
lab var rep_f_`x'_4 "Number of girls grade 4 age `x'"
lab var rep_f_`x'_5 "Number of girls grade 5 age `x'"
lab var rep_f_`x'_6 "Number of girls grade 6 age `x'"
}

rename rep_mf_(#)_1 repeaters_g1_age(#)
rename rep_mf_(#)_2 repeaters_g2_age(#)
rename rep_mf_(#)_3 repeaters_g3_age(#)
rename rep_mf_(#)_4 repeaters_g4_age(#)
rename rep_mf_(#)_5 repeaters_g5_age(#)
rename rep_mf_(#)_6 repeaters_g6_age(#)

rename rep_mf_(##)_1 repeaters_g1_age(##)
rename rep_mf_(##)_2 repeaters_g2_age(##)
rename rep_mf_(##)_3 repeaters_g3_age(##)
rename rep_mf_(##)_4 repeaters_g4_age(##)
rename rep_mf_(##)_5 repeaters_g5_age(##)
rename rep_mf_(##)_6 repeaters_g6_age(##)

rename rep_f_(#)_1 repeatgirl_g1_age(#)
rename rep_f_(#)_2 repeatgirl_g2_age(#)
rename rep_f_(#)_3 repeatgirl_g3_age(#)
rename rep_f_(#)_4 repeatgirl_g4_age(#)
rename rep_f_(#)_5 repeatgirl_g5_age(#)
rename rep_f_(#)_6 repeatgirl_g6_age(#)

rename rep_f_(##)_1 repeatgirl_g1_age(##)
rename rep_f_(##)_2 repeatgirl_g2_age(##)
rename rep_f_(##)_3 repeatgirl_g3_age(##)
rename rep_f_(##)_4 repeatgirl_g4_age(##)
rename rep_f_(##)_5 repeatgirl_g5_age(##)
rename rep_f_(##)_6 repeatgirl_g6_age(##)

forval x=1/6{
egen repeaters_g`x' = rowtotal(repeaters_g`x'_age5 repeaters_g`x'_age6 repeaters_g`x'_age7 repeaters_g`x'_age8 repeaters_g`x'_age9 repeaters_g`x'_age10 repeaters_g`x'_age11 repeaters_g`x'_age12 repeaters_g`x'_age13 repeaters_g`x'_age14), missing
egen repeatgirl_g`x' = rowtotal(repeatgirl_g`x'_age5 repeatgirl_g`x'_age6 repeatgirl_g`x'_age7 repeatgirl_g`x'_age8 repeatgirl_g`x'_age9 repeatgirl_g`x'_age10 repeatgirl_g`x'_age11 repeatgirl_g`x'_age12 repeatgirl_g`x'_age13 repeatgirl_g`x'_age14), missing
}

egen repeaters = rowtotal(repeaters_pre repeaters_g1 repeaters_g2 repeaters_g3 repeaters_g4 repeaters_g5 repeaters_g6), missing
egen repeatgirl = rowtotal(repeatgirl_pre repeatgirl_g1 repeatgirl_g2 repeatgirl_g3 repeatgirl_g4 repeatgirl_g5 repeatgirl_g6), missing

lab var students_pre 	"Number of students in pre-school"
lab var girls_pre  		"Number of girls in pre-school"
lab var students_g1  	"Number of students in grade 1"
lab var girls_g1  		"Number of girls in grade 1"
lab var students_g2  	"Number of students in grade 2"
lab var girls_g2  		"Number of girls in grade 2"
lab var students_g3  	"Number of students in grade 3"
lab var girls_g3  		"Number of girls in grade 3"
lab var students_g4 	"Number of students in grade 4"
lab var girls_g4  		"Number of girls in grade 4"
lab var students_g5  	"Number of students in grade 5"
lab var girls_g5  		"Number of girls in grade 5"
lab var students_g6  	"Number of students in grade 6"
lab var girls_g6  		"Number of girls in grade 6"
lab var students  		"Number of students in total"
lab var girls 			"Number of girls in total"

lab var repeaters_pre 	"Number of repeaters in pre-school"
lab var repeatgirl_pre  "Number of repeating girls in pre-school"
lab var repeaters_g1  	"Number of repeaters in grade 1"
lab var repeatgirl_g1  	"Number of repeating girls in grade 1"
lab var repeaters_g2  	"Number of repeaters in grade 2"
lab var repeatgirl_g2  	"Number of repeating girls in grade 2"
lab var repeaters_g3  	"Number of repeaters in grade 3"
lab var repeatgirl_g3  	"Number of repeating girls in grade 3"
lab var repeaters_g4 	"Number of repeaters in grade 4"
lab var repeatgirl_g4  	"Number of repeating girls in grade 4"
lab var repeaters_g5  	"Number of repeaters in grade 5"
lab var repeatgirl_g5  	"Number of repeating girls in grade 5"
lab var repeaters_g6  	"Number of repeaters in grade 6"
lab var repeatgirl_g6  	"Number of repeating girls in grade 6"
lab var repeaters  		"Number of repeaters in total"
lab var repeatgirl 		"Number of repeating girls in total"

forval x =1/6{
egen classes_g`x' = rowtotal(n_de_turmas_m_`x' n_de_turmas_t_`x' n_de_turmas_n_`x'), missing
egen disabled_g`x' = rowtotal(nec_mf_vis_`x' nec_mf_aud_`x' nec_mf_mot_`x' nec_mf_out_`x'), missing
egen disabgirl_g`x' = rowtotal(nec_f_vis_`x' nec_f_aud_`x' nec_f_mot_`x' nec_f_out_`x'), missing
}

egen disabled_visual = rowtotal(pre_nec_mf_vis nec_mf_vis_1 nec_mf_vis_2 nec_mf_vis_3 nec_mf_vis_4 nec_mf_vis_5 nec_mf_vis_6), missing
egen disabgirl_visual = rowtotal(pre_nec_f_vis nec_f_vis_1 nec_f_vis_2 nec_f_vis_3 nec_f_vis_4 nec_f_vis_5 nec_f_vis_6), missing

egen disabled_audio = rowtotal(pre_nec_mf_aud nec_mf_aud_1 nec_mf_aud_2 nec_mf_aud_3 nec_mf_aud_4 nec_mf_aud_5 nec_mf_aud_6), missing
egen disabgirl_audio = rowtotal(pre_nec_f_aud nec_f_aud_1 nec_f_aud_2 nec_f_aud_3 nec_f_aud_4 nec_f_aud_5 nec_f_aud_6), missing

egen disabled_motor = rowtotal(pre_nec_mf_mot nec_mf_mot_1 nec_mf_mot_2 nec_mf_mot_3 nec_mf_mot_4 nec_mf_mot_5 nec_mf_mot_6), missing
egen disabgirl_motor = rowtotal(pre_nec_f_mot nec_f_mot_1 nec_f_mot_2 nec_f_mot_3 nec_f_mot_4 nec_f_mot_5 nec_f_mot_6), missing

egen disabled_other = rowtotal(pre_nec_mf_out nec_mf_out_1 nec_mf_out_2 nec_mf_out_3 nec_mf_out_4 nec_mf_out_5 nec_mf_out_6), missing
egen disabgirl_other = rowtotal(pre_nec_f_out nec_f_out_1 nec_f_out_2 nec_f_out_3 nec_f_out_4 nec_f_out_5 nec_f_out_6), missing

egen disabled = rowtotal(disabled_visual disabled_audio disabled_motor disabled_other), missing
egen disabgirl = rowtotal(disabgirl_visual disabgirl_audio disabgirl_motor disabgirl_other), missing

egen classes = rowtotal(classes_pre classes_g1 classes_g2 classes_g3 classes_g4 classes_g5 classes_g6), missing

drop pre_nec_mf_vis pre_nec_f_vis pre_nec_mf_aud pre_nec_f_aud pre_nec_mf_mot pre_nec_f_mot pre_nec_mf_out pre_nec_f_out

drop n_de_turmas_m_1 n_de_turmas_m_2 n_de_turmas_m_3 n_de_turmas_m_4 n_de_turmas_m_5 n_de_turmas_m_6 n_de_turnos_m_1 n_de_turnos_m_2 n_de_turnos_m_3 n_de_turnos_m_4 n_de_turnos_m_5 n_de_turnos_m_6 n_de_turmas_t_1 n_de_turmas_t_2 n_de_turmas_t_3 n_de_turmas_t_4 n_de_turmas_t_5 n_de_turmas_t_6 n_de_turnos_t_1 n_de_turnos_t_2 n_de_turnos_t_3 n_de_turnos_t_4 n_de_turnos_t_5 n_de_turnos_t_6 n_de_turmas_n_1 n_de_turmas_n_2 n_de_turmas_n_3 n_de_turmas_n_4 n_de_turmas_n_5 n_de_turmas_n_6 n_de_turnos_n_1 n_de_turnos_n_2 n_de_turnos_n_3 n_de_turnos_n_4 n_de_turnos_n_5 n_de_turnos_n_6
drop nec_mf_vis_1 nec_mf_vis_2 nec_mf_vis_3 nec_mf_vis_4 nec_mf_vis_5 nec_mf_vis_6 nec_f_vis_1 nec_f_vis_2 nec_f_vis_3 nec_f_vis_4 nec_f_vis_5 nec_f_vis_6 nec_mf_aud_1 nec_mf_aud_2 nec_mf_aud_3 nec_mf_aud_4 nec_mf_aud_5 nec_mf_aud_6 nec_f_aud_1 nec_f_aud_2 nec_f_aud_3 nec_f_aud_4 nec_f_aud_5 nec_f_aud_6 nec_mf_mot_1 nec_mf_mot_2 nec_mf_mot_3 nec_mf_mot_4 nec_mf_mot_5 nec_mf_mot_6 nec_f_mot_1 nec_f_mot_2 nec_f_mot_3 nec_f_mot_4 nec_f_mot_5 nec_f_mot_6 nec_mf_out_1 nec_mf_out_2 nec_mf_out_3 nec_mf_out_4 nec_mf_out_5 nec_mf_out_6 nec_f_out_1 nec_f_out_2 nec_f_out_3 nec_f_out_4 nec_f_out_5 nec_f_out_6

label variable classes "Number of classes"
label variable classes_pre "Number of pre-school classes"
label variable classes_g1 "Number of 1st grade classes"
label variable classes_g2 "Number of 2nd grade classes"
label variable classes_g3 "Number of 3rd grade classes"
label variable classes_g4 "Number of 4th grade classes"
label variable classes_g5 "Number of 5th grade classes"
label variable classes_g6 "Number of 6th grade classes"

lab var disabled_pre 		"Number of disabled students in pre-school"
lab var disabgirl_pre 	 	"Number of disabled girls in pre-school"
lab var disabled_g1  		"Number of disabled students in grade 1"
lab var disabgirl_g1  		"Number of disabled girls in grade 1"
lab var disabled_g2  		"Number of disabled students in grade 2"
lab var disabgirl_g2  		"Number of disabled girls in grade 2"
lab var disabled_g3  		"Number of disabled students in grade 3"
lab var disabgirl_g3  		"Number of disabled girls in grade 3"
lab var disabled_g4 		"Number of disabled students in grade 4"
lab var disabgirl_g4  		"Number of disabled girls in grade 4"
lab var disabled_g5  		"Number of disabled students in grade 5"
lab var disabgirl_g5  		"Number of disabled girls in grade 5"
lab var disabled_g6  		"Number of disabled students in grade 6"
lab var disabgirl_g6  		"Number of disabled girls in grade 6"
lab var disabled  			"Number of disabled students in total"
lab var disabgirl 			"Number of disabled girls in total"


egen teachers_prim_until13 = rowtotal(nivprof_mf_6_1 nivprof_mf_6_2 nivprof_mf_6_3 nivprof_mf_78_1 nivprof_mf_78_2 nivprof_mf_78_3 nivprof_mf_910_1 nivprof_mf_910_2 nivprof_mf_910_3 nivprof_mf_111213_1 nivprof_mf_111213_2 nivprof_mf_111213_3), missing
egen teachfem_prim_until13 = rowtotal(nivprof_f_6_1 nivprof_f_6_2 nivprof_f_6_3 nivprof_f_78_1 nivprof_f_78_2 nivprof_f_78_3 nivprof_f_910_1 nivprof_f_910_2 nivprof_f_910_3 nivprof_f_111213_1 nivprof_f_111213_2 nivprof_f_111213_3), missing

egen teachers_prim_uni = rowtotal(nivprof_mf_bach_1 nivprof_mf_bach_2 nivprof_mf_bach_3 nivprof_mf_lic_1 nivprof_mf_lic_2 nivprof_mf_lic_3 nivprof_mf_poslic_1 nivprof_mf_poslic_2 nivprof_mf_poslic_3), missing
egen teachfem_prim_uni = rowtotal(nivprof_f_bach_1 nivprof_f_bach_2 nivprof_f_bach_3 nivprof_f_lic_1 nivprof_f_lic_2 nivprof_f_lic_3 nivprof_f_poslic_1 nivprof_f_poslic_2 nivprof_f_poslic_3), missing

egen teachers_until13 = rowtotal(teachers_prim_until13 teachers_pre_until13), missing
egen teachfem_until13 = rowtotal(teachfem_prim_until13 teachfem_pre_until13), missing

egen teachers_uni = rowtotal(teachers_prim_uni teachers_pre_uni), missing
egen teachfem_uni = rowtotal(teachfem_prim_uni teachfem_pre_uni), missing

egen teachers_prim = rowtotal(teachers_prim_until13 teachers_prim_uni), missing
egen teachfem_prim = rowtotal(teachfem_prim_until13 teachfem_prim_uni), missing

egen teachers2 = rowtotal(teachers_prim teachers_pre), missing
egen teachfem2 = rowtotal(teachfem_prim teachfem_pre), missing


gen teachers_share_uni = teachers_uni/teachers2
gen teachfem_share_uni = teachfem_uni/teachfem2

drop teachers_pre_until13 teachfem_pre_until13 teachers_pre_uni teachfem_pre_uni teachers_pre teachfem_pre teachers_prim_until13 teachfem_prim_until13 teachers_prim_uni teachfem_prim_uni teachers_prim teachfem_prim teachers_uni teachfem_uni teachers2 teachfem2


drop nivprof_mf_6_1 nivprof_mf_6_2 nivprof_mf_6_3 nivprof_mf_6_4 nivprof_mf_6_5 nivprof_f_6_1 nivprof_f_6_2 nivprof_f_6_3 nivprof_f_6_4 nivprof_f_6_5 nivprof_mf_78_1 nivprof_mf_78_2 nivprof_mf_78_3 nivprof_mf_78_4 nivprof_mf_78_5 nivprof_f_78_1 nivprof_f_78_2 nivprof_f_78_3 nivprof_f_78_4 nivprof_f_78_5 nivprof_mf_910_1 nivprof_mf_910_2 nivprof_mf_910_3 nivprof_mf_910_4 nivprof_mf_910_5 nivprof_f_910_1 nivprof_f_910_2 nivprof_f_910_3 nivprof_f_910_4 nivprof_f_910_5 nivprof_mf_111213_1 nivprof_mf_111213_2 nivprof_mf_111213_3 nivprof_mf_111213_4 nivprof_mf_111213_5 nivprof_f_111213_1 nivprof_f_111213_2 nivprof_f_111213_3 nivprof_f_111213_4 nivprof_f_111213_5 nivprof_mf_bach_1 nivprof_mf_bach_2 nivprof_mf_bach_3 nivprof_mf_bach_4 nivprof_mf_bach_5 nivprof_f_bach_1 nivprof_f_bach_2 nivprof_f_bach_3 nivprof_f_bach_4 nivprof_f_bach_5 nivprof_mf_lic_1 nivprof_mf_lic_2 nivprof_mf_lic_3 nivprof_mf_lic_4 nivprof_mf_lic_5 nivprof_f_lic_1 nivprof_f_lic_2 nivprof_f_lic_3 nivprof_f_lic_4 nivprof_f_lic_5 nivprof_mf_poslic_1 nivprof_mf_poslic_2 nivprof_mf_poslic_3 nivprof_mf_poslic_4 nivprof_mf_poslic_5 nivprof_f_poslic_1 nivprof_f_poslic_2 nivprof_f_poslic_3 nivprof_f_poslic_4 nivprof_f_poslic_5

egen teachers_pre = rowtotal(idadeprof_mf_com_ini_1 idadeprof_mf_com_ini_2 idadeprof_mf_com_ini_3 idadeprof_mf_com_ini_4 idadeprof_mf_com_ini_5 idadeprof_mf_com_ini_6 idadeprof_mf_sem_ini_1 idadeprof_mf_sem_ini_2 idadeprof_mf_sem_ini_3 idadeprof_mf_sem_ini_4 idadeprof_mf_sem_ini_5 idadeprof_mf_sem_ini_6),missing
egen teachfem_pre = rowtotal(idadeprof_f_com_ini_1 idadeprof_f_com_ini_2 idadeprof_f_com_ini_3 idadeprof_f_com_ini_4 idadeprof_f_com_ini_5 idadeprof_f_com_ini_6 idadeprof_f_sem_ini_1 idadeprof_f_sem_ini_2 idadeprof_f_sem_ini_3 idadeprof_f_sem_ini_4 idadeprof_f_sem_ini_5 idadeprof_f_sem_ini_6),missing

egen teachers_prim = rowtotal(idadeprof_mf_com_1 idadeprof_mf_com_2 idadeprof_mf_com_3 idadeprof_mf_com_4 idadeprof_mf_com_5 idadeprof_mf_com_6 idadeprof_mf_sem_1 idadeprof_mf_sem_2 idadeprof_mf_sem_3 idadeprof_mf_sem_4 idadeprof_mf_sem_5 idadeprof_mf_sem_6 ), missing
egen teachfem_prim = rowtotal(idadeprof_f_com_1 idadeprof_f_com_2 idadeprof_f_com_3 idadeprof_f_com_4 idadeprof_f_com_5 idadeprof_f_com_6 idadeprof_f_sem_1 idadeprof_f_sem_2 idadeprof_f_sem_3 idadeprof_f_sem_4 idadeprof_f_sem_5 idadeprof_f_sem_6), missing

egen teachers = rowtotal(teachers_pre teachers_prim), missing
egen teachfem = rowtotal(teachfem_pre teachfem_prim), missing

drop idadeprof_mf_com_ini_1 idadeprof_mf_com_ini_2 idadeprof_mf_com_ini_3 idadeprof_mf_com_ini_4 idadeprof_mf_com_ini_5 idadeprof_mf_com_ini_6  idadeprof_f_com_ini_1 idadeprof_f_com_ini_2 idadeprof_f_com_ini_3 idadeprof_f_com_ini_4 idadeprof_f_com_ini_5 idadeprof_f_com_ini_6 idadeprof_mf_sem_ini_1 idadeprof_mf_sem_ini_2 idadeprof_mf_sem_ini_3 idadeprof_mf_sem_ini_4 idadeprof_mf_sem_ini_5 idadeprof_mf_sem_ini_6 idadeprof_f_sem_ini_1 idadeprof_f_sem_ini_2 idadeprof_f_sem_ini_3 idadeprof_f_sem_ini_4 idadeprof_f_sem_ini_5 idadeprof_f_sem_ini_6
drop idadeprof_mf_com_1 idadeprof_mf_com_2 idadeprof_mf_com_3 idadeprof_mf_com_4 idadeprof_mf_com_5 idadeprof_mf_com_6  idadeprof_f_com_1 idadeprof_f_com_2 idadeprof_f_com_3 idadeprof_f_com_4 idadeprof_f_com_5 idadeprof_f_com_6  idadeprof_mf_sem_1 idadeprof_mf_sem_2 idadeprof_mf_sem_3 idadeprof_mf_sem_4 idadeprof_mf_sem_5 idadeprof_mf_sem_6 idadeprof_f_sem_1 idadeprof_f_sem_2 idadeprof_f_sem_3 idadeprof_f_sem_4 idadeprof_f_sem_5 idadeprof_f_sem_6


replace manu_alu_6_3 = 0 if manu_alu_6_3==999

rename manu_prof_1_(#) manu_teacher_g1_(#)
rename manu_alu_1_(#) manu_student_g1_(#)
rename manu_prof_2_(#) manu_teacher_g2_(#)
rename manu_alu_2_(#) manu_student_g2_(#)
rename manu_prof_3_(#) manu_teacher_g3_(#)
rename manu_alu_3_(#) manu_student_g3_(#)
rename manu_prof_4_(#) manu_teacher_g4_(#)
rename manu_alu_4_(#) manu_student_g4_(#)
rename manu_prof_5_(#) manu_teacher_g5_(#)
rename manu_alu_5_(#) manu_student_g5_(#)
rename manu_prof_6_(#) manu_teacher_g6_(#)
rename manu_alu_6_(#) manu_student_g6_(#)

lab var manu_teacher_pre "Number of received teacher manuals pre-school"
lab var manu_student_pre "Number of received student manuals pre-school"

forval x=1/4{
lab var manu_teacher_g1_`x' "Number of teacher manuals grade 1 type`x'"
lab var manu_student_g1_`x' "Number of student manuals grade 1 type`x'"
lab var manu_teacher_g2_`x' "Number of teacher manuals grade 2 type`x'"
lab var manu_student_g2_`x' "Number of student manuals grade 2 type`x'"
lab var manu_teacher_g3_`x' "Number of teacher manuals grade 3 type`x'"
lab var manu_student_g3_`x' "Number of student manuals grade 3 type`x'"
lab var manu_teacher_g4_`x' "Number of teacher manuals grade 4 type`x'"
lab var manu_student_g4_`x' "Number of student manuals grade 4 type`x'"
lab var manu_teacher_g5_`x' "Number of teacher manuals grade 5 type`x'"
lab var manu_student_g5_`x' "Number of student manuals grade 5 type`x'"
lab var manu_teacher_g6_`x' "Number of teacher manuals grade 6 type`x'"
lab var manu_student_g6_`x' "Number of student manuals grade 6 type`x'"
}

/*
type 1 is portuguese language
type 2 is mathematics
type 3 is science
type 4 is others
*/

rename data_dia  							date_day
rename data_mes  							date_month
rename data_ano								date_year

label variable date_day "Date of completing the form (DAY)"
label variable date_month "Date of completing the form (MONTH)"
label variable date_year "Date of completing the form (YEAR)"

drop final

order classes_pre classes_g1 classes_g2 classes_g3 classes_g4 classes_g5 classes_g6 classes, after(school_assembly_active)

order students_g1 students_g2 students_g3 students_g4 students_g5 students_g6 students,after(students_pre )
order girls_g1 girls_g2 girls_g3 girls_g4 girls_g5 girls_g6 girls, after(girls_pre)
order repeaters_g1 repeaters_g2 repeaters_g3 repeaters_g4 repeaters_g5 repeaters_g6 repeaters,after(repeaters_pre)
order repeatgirl_g1 repeatgirl_g2 repeatgirl_g3 repeatgirl_g4 repeatgirl_g5 repeatgirl_g6 repeatgirl,after(repeatgirl_pre)

order disabled_pre disabled_g1 disabled_g2 disabled_g3 disabled_g4 disabled_g5 disabled_g6 disabled, after(repeatgirl)
order disabgirl_pre disabgirl_g1 disabgirl_g2 disabgirl_g3 disabgirl_g4 disabgirl_g5 disabgirl_g6 disabgirl, after(disabled)

order manu_teacher_g1_1 manu_teacher_g1_2 manu_teacher_g1_3 manu_teacher_g1_4 manu_teacher_g2_1 manu_teacher_g2_2 manu_teacher_g2_3 manu_teacher_g2_4 manu_teacher_g3_1 manu_teacher_g3_2 manu_teacher_g3_3 manu_teacher_g3_4 manu_teacher_g4_1 manu_teacher_g4_2 manu_teacher_g4_3 manu_teacher_g4_4 manu_teacher_g5_1 manu_teacher_g5_2 manu_teacher_g5_3 manu_teacher_g5_4 manu_teacher_g6_1 manu_teacher_g6_2 manu_teacher_g6_3 manu_teacher_g6_4,after(manu_teacher_pre)
order manu_student_g1_1 manu_student_g1_2 manu_student_g1_3 manu_student_g1_4 manu_student_g2_1 manu_student_g2_2 manu_student_g2_3 manu_student_g2_4 manu_student_g3_1 manu_student_g3_2 manu_student_g3_3 manu_student_g3_4 manu_student_g4_1 manu_student_g4_2 manu_student_g4_3 manu_student_g4_4 manu_student_g5_1 manu_student_g5_2 manu_student_g5_3 manu_student_g5_4 manu_student_g6_1 manu_student_g6_2 manu_student_g6_3 manu_student_g6_4,after(manu_student_pre)

drop students_g1_age5 students_g2_age5 students_g3_age5 students_g4_age5 students_g5_age5 students_g6_age5 girls_g1_age5 girls_g2_age5 girls_g3_age5 girls_g4_age5 girls_g5_age5 girls_g6_age5 students_g1_age6 students_g2_age6 students_g3_age6 students_g4_age6 students_g5_age6 students_g6_age6 girls_g1_age6 girls_g2_age6 girls_g3_age6 girls_g4_age6 girls_g5_age6 girls_g6_age6 students_g1_age7 students_g2_age7 students_g3_age7 students_g4_age7 students_g5_age7 students_g6_age7 girls_g1_age7 girls_g2_age7 girls_g3_age7 girls_g4_age7 girls_g5_age7 girls_g6_age7 students_g1_age8 students_g2_age8 students_g3_age8 students_g4_age8 students_g5_age8 students_g6_age8 girls_g1_age8 girls_g2_age8 girls_g3_age8 girls_g4_age8 girls_g5_age8 girls_g6_age8 students_g1_age9 students_g2_age9 students_g3_age9 students_g4_age9 students_g5_age9 students_g6_age9 girls_g1_age9 girls_g2_age9 girls_g3_age9 girls_g4_age9 girls_g5_age9 girls_g6_age9 students_g1_age10 students_g2_age10 students_g3_age10 students_g4_age10 students_g5_age10 students_g6_age10 girls_g1_age10 girls_g2_age10 girls_g3_age10 girls_g4_age10 girls_g5_age10 girls_g6_age10 students_g1_age11 students_g2_age11 students_g3_age11 students_g4_age11 students_g5_age11 students_g6_age11 girls_g1_age11 girls_g2_age11 girls_g3_age11 girls_g4_age11 girls_g5_age11 girls_g6_age11 students_g1_age12 students_g2_age12 students_g3_age12 students_g4_age12 students_g5_age12 students_g6_age12 girls_g1_age12 girls_g2_age12 girls_g3_age12 girls_g4_age12 girls_g5_age12 girls_g6_age12 students_g1_age13 students_g2_age13 students_g3_age13 students_g4_age13 students_g5_age13 students_g6_age13 girls_g1_age13 girls_g2_age13 girls_g3_age13 girls_g4_age13 girls_g5_age13 girls_g6_age13 students_g1_age14 students_g2_age14 students_g3_age14 students_g4_age14 students_g5_age14 students_g6_age14 girls_g1_age14 girls_g2_age14 girls_g3_age14 girls_g4_age14 girls_g5_age14 girls_g6_age14 repeaters_g1_age5 repeaters_g2_age5 repeaters_g3_age5 repeaters_g4_age5 repeaters_g5_age5 repeaters_g6_age5 repeatgirl_g1_age5 repeatgirl_g2_age5 repeatgirl_g3_age5 repeatgirl_g4_age5 repeatgirl_g5_age5 repeatgirl_g6_age5 repeaters_g1_age6 repeaters_g2_age6 repeaters_g3_age6 repeaters_g4_age6 repeaters_g5_age6 repeaters_g6_age6 repeatgirl_g1_age6 repeatgirl_g2_age6 repeatgirl_g3_age6 repeatgirl_g4_age6 repeatgirl_g5_age6 repeatgirl_g6_age6 repeaters_g1_age7 repeaters_g2_age7 repeaters_g3_age7 repeaters_g4_age7 repeaters_g5_age7 repeaters_g6_age7 repeatgirl_g1_age7 repeatgirl_g2_age7 repeatgirl_g3_age7 repeatgirl_g4_age7 repeatgirl_g5_age7 repeatgirl_g6_age7 repeaters_g1_age8 repeaters_g2_age8 repeaters_g3_age8 repeaters_g4_age8 repeaters_g5_age8 repeaters_g6_age8 repeatgirl_g1_age8 repeatgirl_g2_age8 repeatgirl_g3_age8 repeatgirl_g4_age8 repeatgirl_g5_age8 repeatgirl_g6_age8 repeaters_g1_age9 repeaters_g2_age9 repeaters_g3_age9 repeaters_g4_age9 repeaters_g5_age9 repeaters_g6_age9 repeatgirl_g1_age9 repeatgirl_g2_age9 repeatgirl_g3_age9 repeatgirl_g4_age9 repeatgirl_g5_age9 repeatgirl_g6_age9 repeaters_g1_age10 repeaters_g2_age10 repeaters_g3_age10 repeaters_g4_age10 repeaters_g5_age10 repeaters_g6_age10 repeatgirl_g1_age10 repeatgirl_g2_age10 repeatgirl_g3_age10 repeatgirl_g4_age10 repeatgirl_g5_age10 repeatgirl_g6_age10 repeaters_g1_age11 repeaters_g2_age11 repeaters_g3_age11 repeaters_g4_age11 repeaters_g5_age11 repeaters_g6_age11 repeatgirl_g1_age11 repeatgirl_g2_age11 repeatgirl_g3_age11 repeatgirl_g4_age11 repeatgirl_g5_age11 repeatgirl_g6_age11 repeaters_g1_age12 repeaters_g2_age12 repeaters_g3_age12 repeaters_g4_age12 repeaters_g5_age12 repeaters_g6_age12 repeatgirl_g1_age12 repeatgirl_g2_age12 repeatgirl_g3_age12 repeatgirl_g4_age12 repeatgirl_g5_age12 repeatgirl_g6_age12 repeaters_g1_age13 repeaters_g2_age13 repeaters_g3_age13 repeaters_g4_age13 repeaters_g5_age13 repeaters_g6_age13 repeatgirl_g1_age13 repeatgirl_g2_age13 repeatgirl_g3_age13 repeatgirl_g4_age13 repeatgirl_g5_age13 repeatgirl_g6_age13 repeaters_g1_age14 repeaters_g2_age14 repeaters_g3_age14 repeaters_g4_age14 repeaters_g5_age14 repeaters_g6_age14 repeatgirl_g1_age14 repeatgirl_g2_age14 repeatgirl_g3_age14 repeatgirl_g4_age14 repeatgirl_g5_age14 repeatgirl_g6_age14

rename classes_outside outside_classes



drop school_name director_name director_age director_edu director_tel director_spec director_hoursteach director_hoursdir deputy_name deputy_age deputy_edu deputy_tel deputy_spec deputy_hoursteach deputy_hoursdir school_type

rename desks_teacher teacher_desks

rename places_students 		seats
rename seats_desks_students	desks

gen bathroom = 0
replace bathroom = 1 if  bathrooms_students>0
replace bathroom = 1 if  bathrooms_boys>0
replace bathroom = 1 if  bathrooms_girls>0
replace bathroom = 1 if  bathrooms_teachers>0
replace bathroom = 1 if  bathrooms_men>0
replace bathroom = 1 if  bathrooms_women>0

order 	school_id 											/// School ID
		date_day date_month date_year						/// Date
		classes_pre classes_g1 classes_g2 classes_g3 		/// Classes
		classes_g4 classes_g5 classes_g6 classes			///
		students_pre students_g1 students_g2 students_g3 	/// Students
		students_g4 students_g5 students_g6 students		///
		girls_pre  girls_g1  girls_g2  girls_g3  girls_g4  	/// Female students
		girls_g5  girls_g6 girls							///
		repeaters_g1 repeaters_g2 repeaters_g3 repeaters_g4 /// Repeaters
		repeaters_g5 repeaters_g6 repeaters					///
		repeatgirl_g1 repeatgirl_g2 repeatgirl_g3 			/// Female repeaters
		repeatgirl_g4 repeatgirl_g5 repeatgirl_g6 			///
		repeatgirl											///
		disabled_pre disabled_g1 disabled_g2 disabled_g3 	/// Disabled students
		disabled_g4 disabled_g5 disabled_g6					///
		disabled_visual disabled_audio disabled_motor 		///
		disabled_other disabled								///
		disabgirl_pre disabgirl_g1 disabgirl_g2 			/// Female disabled students
		disabgirl_g3 disabgirl_g4 disabgirl_g5 				///
		disabgirl_g6 disabgirl_visual disabgirl_audio 		///
		disabgirl_motor disabgirl_other disabgirl			///
		teachers_pre teachers_prim teachers 				/// Teachers
		teachers_share_uni									///
		teachfem_pre teachfem_prim teachfem 				/// Female Teachers
		teachfem_share_uni									///
		secretaries guards cleaners other_teachers 			/// Staff
		other_empl											///
		secretaries_fem guards_fem cleaners_fem 			/// Female staff
		other_teachers_fem other_empl_fem					///
		classrooms_def_blocks classrooms_prov_blocks 		/// Classrooms
		classrooms_impr_blocks classrooms_def_cement 		///
		classrooms_prov_cement classrooms_impr_cement 		///
		classrooms_def_other classrooms_prov_other 			///
		classrooms_impr_other classrooms_def 				///
		classrooms_prov classrooms_impr classrooms			///
		desks seats chalkboards teacher_desks				/// Furniture
		highest_grade sportfield outside_classes 			/// Some characteristics
		bathroom canteen water electricity					///
	classrooms_annex_def_blocks classrooms_annex_def_cement 	/// Annex classrooms (2018 only)
	classrooms_annex_def_other classrooms_annex_prov_blocks 	///
	classrooms_annex_prov_cement classrooms_annex_prov_other 	///
	classrooms_annex_impr_blocks classrooms_annex_impr_cement 	///
	classrooms_annex_impr_other classrooms_annex_def 			///
	classrooms_annex_prov classrooms_annex_impr 				///
	classrooms_annex classrooms_plusannex						///
		classrooms2 classes_mixed bathrooms_students 			/// Other school characteristics (2018 only)
		bathrooms_boys bathrooms_girls bathrooms_teachers 		///
		bathrooms_men bathrooms_women computers 				///
		computers_teachers computers_students houses 			///
		houses_teachers hourses_director 						///
		residualwater_deposit waste_deposit pat_material 		///
		pat zip supply_center establishment_year 				///
		distance_supply_center distance_municipal_center 		///
		distance_provincial_center parents_committee 			///
		parents_committee_active school_assembly 				///
		school_assembly_active									///
		manu_teacher_pre manu_teacher_g1_1 manu_teacher_g1_2 	/// Manuals received (2018 only)
		manu_teacher_g1_3 manu_teacher_g1_4 manu_teacher_g2_1 	///
		manu_teacher_g2_2 manu_teacher_g2_3 manu_teacher_g2_4 	///
		manu_teacher_g3_1 manu_teacher_g3_2 manu_teacher_g3_3 	///
		manu_teacher_g3_4 manu_teacher_g4_1 manu_teacher_g4_2 	///
		manu_teacher_g4_3 manu_teacher_g4_4 manu_teacher_g5_1 	///
		manu_teacher_g5_2 manu_teacher_g5_3 manu_teacher_g5_4 	///
		manu_teacher_g6_1 manu_teacher_g6_2 manu_teacher_g6_3 	///
		manu_teacher_g6_4 manu_student_pre manu_student_g1_1 	///
		manu_student_g1_2 manu_student_g1_3 manu_student_g1_4 	///
		manu_student_g2_1 manu_student_g2_2 manu_student_g2_3 	///
		manu_student_g2_4 manu_student_g3_1 manu_student_g3_2 	///
		manu_student_g3_3 manu_student_g3_4 manu_student_g4_1 	///
		manu_student_g4_2 manu_student_g4_3 manu_student_g4_4 	///
		manu_student_g5_1 manu_student_g5_2 manu_student_g5_3 	///
		manu_student_g5_4 manu_student_g6_1 manu_student_g6_2 	///
		manu_student_g6_3 manu_student_g6_4

replace manu_student_pre = . if manu_student_pre==999
replace date_day = . if date_day==99
replace date_month = . if date_month==99
replace date_year = 2018

rename * A18_*
rename A18_school_id school_id

drop A18_repeaters_pre A18_repeatgirl_pre A18_teachers_until13 A18_teachfem_until13

save "$Endline_dtRaw/_intermediate files/admin18.dta", replace





********************************************************************************
********************************************************************************









// merging the three data sets

use "$Baseline_dtRaw/_intermediate files/admin16.dta", clear

merge 1:1 school_id using "$Endline_dtRaw/_intermediate files/admin17.dta"
drop _merge
merge 1:1 school_id using "$Endline_dtRaw/_intermediate files/admin18.dta"
drop _merge

lab var A16_teachers "Total number of teachers"
lab var A16_teachers_share_uni "Share teachers with college degree"
lab var A16_teachfem "Total number of female teachers"
lab var A16_teachfem_share_uni "Share female teachers with college degree"
lab var A17_teachers "Total number of teachers"
lab var A17_teachers_share_uni "Share teachers with college degree"
lab var A17_teachfem "Total number of female teachers"
lab var A17_teachfem_share_uni "Share female teachers with college degree"
lab var A18_disabled_visual "Number of students with visual disability"
lab var A18_disabled_audio "Number of students with auditory disability"
lab var A18_disabled_motor "Number of students with motor disability"
lab var A18_disabled_other "Number of students with other disability"
lab var A18_disabgirl_visual "Number of girls with visual disability"
lab var A18_disabgirl_audio "Number of girls with auditory disability"
lab var A18_disabgirl_motor "Number of girls with motor disability"
lab var A18_disabgirl_other "Number of girls with other disability"
lab var A18_teachers_pre "Total number of pre school teachers"
lab var A18_teachers_prim "Total number of primary school teachers"
lab var A18_teachers "Total number of teachers"
lab var A18_teachers_share_uni "Share teachers with college degree"
lab var A18_teachfem_pre "Total number of female pre school teachers"
lab var A18_teachfem_prim "Total number of female primary school teachers"
lab var A18_teachfem "Total number of female teachers"
lab var A18_teachfem_share_uni "Share female teachers with college degree"
lab var A18_bathroom "School has bathroom"


save "$Endline_dtRaw/_intermediate files/admin.dta", replace
